[英]How to concatenate the row names of a data frame with a special character?
I would like to concatenate the row names of a data frame with a "+" to return a string. 我想用“ +”连接数据框的行名以返回字符串。 For example 例如
head(USArrests)
Murder Assault UrbanPop Rape
Alabama 13.2 236 58 21.2
Alaska 10.0 263 48 44.5
Arizona 8.1 294 80 31.0
Arkansas 8.8 190 50 19.5
California 9.0 276 91 40.6
Colorado 7.9 204 78 38.7
My goal is to get 我的目标是
goal = Alabama+Alaska+Arizona+Arkansas+California+Colorado+...
I tried 我试过了
goal = paste0(rownames(USArrests), sep="+")
head(goal)
[1] "Alabama+" "Alaska+" "Arizona+" "Arkansas+" "California+" "Colorado+"
I am relatively new to R and am lost on how to get the one I wanted. 我对R还是比较陌生,对如何获得想要的迷路了。 Could someone help me? 有人可以帮我吗? Thanks! 谢谢!
paste(rownames(USArrests), collapse="+")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.