0

one quick question

picture a data frame like

data=data.frame(x=c(1,2,3), y=c(4,5,6), Genes=c("AHS;AKS;AHS","AHS;IO","HU"))

so i want to plot x and y

plot(x,y) 

and do the label for the dots like this

text(data$x+0.2,data$y+0.2,labels=data$Genes)

BUT i dont want to use all arguments from the genes column ONLY the first one (e.g. before the ";") Can u please help me with that? This is only an example, i have already read my data in with read.delim, so i cannot do a specific "read in" with string separation.

4

1 回答 1

1

根据我的评论,您可以使用gsub

gsub('^([A-Z]+);.*$', '\\1', data$Genes)

你也可以使用strsplit

unlist(lapply(strsplit(data$Genes, ';'), '[', 1))

但这很恶心...

它还可能值得一提的是,该stringr包将大量这些字符串处理函数收集到一个具有可预测语法和名称的地方。

于 2012-11-28T20:08:40.063 回答