1. 程式人生 > >2-7 R語言基礎 數據框

2-7 R語言基礎 數據框

score col true data gen matrix frame [1] 基礎

#數據框

> df <- data.frame(id=c(1,2,3,4),name=c("a","b","c","d"),gender=c(TRUE,TRUE,FALSE,FALSE))
> nrow(df) #4行
[1] 4


> ncol(df) #3列
[1] 3


> df2 <- data.frame(id=c(1,2,3,4),score=c(80,86,90,100))
> df2
id score
1 1 80
2 2 86
3 3 90
4 4 100


> data.matrix(df2)
id score
[1,] 1 80
[2,] 2 86
[3,] 3 90
[4,] 4 100

2-7 R語言基礎 數據框