行名& R中的列名 [英] Row names & column names in R

查看:122
本文介绍了行名& R中的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下函数对是否产生完全相同的结果?

Do the following function pairs generate exactly the same results?

对1)names()& colnames()

对2)rownames()& row.names()

推荐答案

正如奥斯卡·王尔德(Oscar Wilde)所说

As Oscar Wilde said

一致性是该产品的最后避难所 缺乏想象力.

Consistency is the last refuge of the unimaginative.

R更像是一种进化的语言,而不是设计的语言,因此发生了这些事情. names()colnames()data.frame上起作用,但names()在矩阵上不起作用:

R is more of an evolved rather than designed language, so these things happen. names() and colnames() work on a data.frame but names() does not work on a matrix:

R> DF <- data.frame(foo=1:3, bar=LETTERS[1:3])
R> names(DF)
[1] "foo" "bar"
R> colnames(DF)
[1] "foo" "bar"
R> M <- matrix(1:9, ncol=3, dimnames=list(1:3, c("alpha","beta","gamma")))
R> names(M)
NULL
R> colnames(M)
[1] "alpha" "beta"  "gamma"
R> 

这篇关于行名&amp; R中的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆