OK, we now have a data file with simple text format (either from some simulation or from Excel). After starting up R, type in the following commands in the R prompt ('>').
read.table()
dat.in <- read.table("data.txt", header=T, sep="\t")
> dat.in <- read.table("/Users/naoki/doc/analysis/data.txt", header=T)Or use
setwd()
to set the current working directory or the R process.
> getwd() # print out the current working directory > setwd("/Users/naoki/doc/analysis/") > getwd() > dat.in <- read.table("data.txt", header=T)Or you can do the same thing if you are using GUI R.
From the menu, select
Misc -> Changing Working Directory ...
And navigate the file system to find the directory which CONTAINS the data file.
names(dat.in)
This will show you the list of column names.
dim(dat.in)
This will show you the dimension (size) of data set: number of rows and columns.
What we have done above is that you used the command (function) read.table(), and the results of this command (data read in the way R can understand) is stored in a container called dat.in.
<-
is called an assignment (it looks like an arrow). The results
of read.table() is assigned to dat.in.
You can use whatever name for this storage container (I chose dat.in). Also, R can import multiple files. For example if you have two files to read in, you can store one set of data in simDat and the othe set in obsDat.
This storage container of spread-sheet like data is called data frame, which we will talk more in the next section.