码迷,mamicode.com
首页 > 其他好文 > 详细

Get and Set Column/Row Names for Data Frames

时间:2017-10-07 23:35:38      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:for   cto   frame   names   www   title   ase   blog   htm   


row.names(x)
row.names(x) <- value

 

rownames(x, do.NULL = TRUE, prefix = "row")

rownames(x) <- value

colnames(x, do.NULL = TRUE, prefix = "col")

colnames(x) <- value

####################################
results <- data.frame(matrix(c(1,2,3,4),nrow=2,ncol=2))
rownames(results) <- c("a","b")
colnames(results) <- c("c","d")
attr(results,"title") <- "aaa"
results

 

#####################################

> colnames(data)
[1] "col1" "col2" "col3"
>
> # set the name of column 2
> colnames(data)[2] <- ‘column 2‘
> colnames(data)
[1] "col1"     "column 2" "col3"
>     
> # you can assign all of the columns at once, if you wish
> colnames(data) <- c( ‘col 1‘, ‘col 2‘, ‘col 3‘)
> colnames(data)
[1] "col 1" "col 2" "col 3"
> str(data)
‘data.frame‘: 2 obs. of  3 variables:
$ col 1: Factor w/ 2 levels "1,233","470": 1 2
$ col 2: Factor w/ 2 levels " $1,113.22"," $12.79": 2 1
$ col 3: Factor w/ 2 levels " $0.12"," $1,333,233.17": 2 1


REF:
https://stackoverflow.com/questions/2281353/row-names-column-names-in-r

http://www.astrostatistics.psu.edu/su07/R/html/base/html/colnames.html

http://earlh.com/blog/2009/06/29/column-names-of-r-data-frames/

 

Get and Set Column/Row Names for Data Frames

标签:for   cto   frame   names   www   title   ase   blog   htm   

原文地址:http://www.cnblogs.com/emanlee/p/7636060.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!