2. Basic things to know
• You have to get data(there are two ways)
– data <- read.csv(file.choose())
– data <- read.table(“clipboard”,header=T)
• Notice: this one involves the copy board to restore the
data and there should be header for each variables.
• You have to save data
– write.table(“c:/users/admin/desktop/whatever.csv
”,sep=“,”)
• Sep means the way how data are separated.
6. Basic data management
• In R you use commands to manage data
– data$V1
• This command will get you to the data and control
variable V1
– data[c(1)]
• This command will get you to the data and control the
first variable.
– data[c(1:10)]
• This command will get you to the data and control the
first to tenth variables.
7. Recode functions
• When dealing with data, we may need to recode
them from one value to another
– For example, you have a variable named Gender, but
the values are like “male” and “female”. If you want to
do statistical analysis, you may want to recode them
into 0 and 1 so that the computer can actually
recognize it.
• Use the following command
– data$Gender[data$Gender==“male”] <- 0
– data$Gender[data$Gender==“female”] <- 1
• Whatever is inside the [] symbol is the logical conditions.