Categories:
Cloud (204)
Entertainment (11)
Facebook (43)
General (50)
Life (31)
Programming (64)
Technology (430)
Testing (4)
Tools (488)
Twitter (5)
Wearable (26)
Web Design (44)
Collections:
Other Resources:
Data Structure - Data Frame
What is a Data Frame?
✍: FYIcenter.com
Data Frame is a generalization of matrix where columns
may have different data types.
Technically, a data frame is a special list.
1. Create a factor object with the data.frame() function -
> name = c("Lori", "Mike", "Nill", "Sofi")
> sex = factor( c("F", "M", "M", "F") )
> age = c(21, 33, 25, 28)
> frame = data.frame(name, sex, age)
> frame
name sex age
1 Lori F 21
2 Mike M 33
3 Nill M 25
4 Sofi F 28
> typeof(frame)
[1] "list"
> is.data.frame(frame)
[1] TRUE
> is.list(frame)
[1] TRUE
> is.vector(frame)
[1] FALSE
2. Using data frame as a list -
> length(frame) [1] 3 > frame[1] name 1 Lori 2 Mike 3 Nill 4 Sofi > frame[[1]] [1] "Lori" "Mike" "Nill" "Sofi" > frame[[1]][2] [1] "Mike"
3. Using data frame as a matrix -
> dim(frame) [1] 4 3 > frame[1,] name sex age 1 Lori F 21 > frame[2:3,] name sex age 2 Mike M 33 3 Nill M 25 > frame[,1] [1] "Lori" "Mike" "Nill" "Sofi" > frame[, "name"] [1] "Lori" "Mike" "Nill" "Sofi"
A data frame is like a table in a database.
2023-05-31, 908🔥, 0💬
Popular Posts:
What is the difference between a Web page and a Single File Web Page? Word supports 2 Web page forma...
What is a PowerPoint Template (.potx) File? What is the difference between .potx and .pptx files? A ...
How to start to troubleshoot my Actiontec GT784WNV Modem? I am not able to access Internet. If you a...
Where to find answers to frequently asked questions on Microsoft Teams? Here is a list of frequently...
How can I create a Personal Folders File (.pst) to store messages, contacts and other types of Outlo...