开发者

R convert a column in a table to a list separated by ";"

Input

gendat <- read.table(textConnection("Gene Trea开发者_StackOverflowtment1  Treatment2
aaa  bbb         ccc
ddd  eee         fff
ggg  hhh         iii"), header=TRUE)

Output for the column "Treatment1"

bbb; eee; hhh

I want to select only column "Treatment1" and generate a list contains all cells in this column but separated by a ; and a space

Please kindly instruct how to do so with R. Thanks.


I thought ,incorrectly it turns out, that sep in paste() could only be one character. You said "list" but I am guessing you did not mean that in the narrow R sense of the term:

> paste(gendat$Treatment1, collapse="; ")
[1] "bbb; eee; hhh"


R comes with excellent manuals. I suggest you read "An introduction to R", paying special attention to chapters 2.6 and 6.1

http://cran.r-project.org/doc/manuals/R-intro.pdf

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜