Section 9 Dataframe
9.1 Function
Example vector: x <- c(1:10); y <- rep(c('M','F'), each=5); z <- rep(c(T,F), length=10)
Function | Explanation | Example |
---|---|---|
data.frame |
Create a data.frame | DF <- data.frame(Age=x, Sex=y, Vac=z) |
as.data.frame |
Coerce into a data.frame | as.data.frame(DF) |
is.data.frame |
Check if its argument is a data.frame | is.data.frame(DF) |
dim |
Get the dimension of a data.frame | dim(DF) |
dimnames |
A dimnames attribute for a data.frame | dimnames(DF) |
names, colnames | Column names of a data.frame | names(DF) |
row.names, rownames | Row names of a data.frame | row.names(DF) |
attributes |
Attributes of a data.frame | attributes(DF) |
9.2 Example
?data.frame
x <- c(1:10)
y <- rep(c('M','F'), each=5)
z <- rep(c(T,F), length=10)
DF <- data.frame(Age=x, Sex=y, Vac=z)
DF
is.data.frame(DF)
dim(DF)
dimnames(DF)
names(DF)
colnames(DF)
rownames(DF)
attributes(DF)
str(DF)
Note: Data frames are usually created by reading in a dataset using the functions read.table()
or read.csv()
. We will cover this later.