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. Could someone help me? Thanks!
我对R来说相对较新,我很失落如何获得我想要的那个。有人能帮帮我吗?谢谢!
1 个解决方案
#1
2
paste(rownames(USArrests), collapse="+")
#1
2
paste(rownames(USArrests), collapse="+")