开发者

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

开发者 https://www.devze.com 2023-03-01 00:45 出处:网络
Input gendat <- read.table(textConnection(\"Gene Trea开发者_StackOverflowtment1Treatment2 aaabbbccc

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

精彩评论

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