Section 10 Operation on Dataframe
10.1 Example
?data.frame
set.seed(1234)
x <- c(1:20)
y <- sample(c('M','F'), size=20, replace=TRUE)
z <- rep(c(T,F), length=20)Create a data.frame
Describe the data.frame
Add a column to the data.frame:
v <- rep(1:4, each=5)Delete a column from the data.frame: Delete the column
vRename columns in the data.frame:
Age, Sex, VacReorder columns in the data.frame:
Age, Vac, SexGet a subset of data.frame:
Age >= 5, only columnsAge, VacChange the reference level of a factor: Change the reference level of
SexasMChange the order of a factor levels: Change the order of
SexasF, MChange the names of a factor levels: Change the names of levels of
SexasFemale, Male