4Data Input and Dataframes
In this chapter, we will explore how to import data into
and then, when it has arrived, how to manipulate its default structure, known as a dataframe. Obviously, data can be typed directly into
using c () and other functions, but we will assume from now on that the data is held in a file, usually a spreadsheet.
4.1 Working directory
always has a working directory which is where it will attempt to read and write files. It's easy to find the current working directory:
The simplest way to organise things is to set the working directory to wherever (directory or folder) the project we are working on is based, as soon as
is started. Presumably, any data files we import will already be located there and then when we save a program, plot, data file, etc., it will automatically be saved to the same place. There are a number of ways to do this. Let us assume that the directory is C:/project. Then we could type:
Alternatively, in RStudio, we can click on ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access