On Aug 27, 2012, at 1:40 PM, Sapana Lohani wrote:

Hi, my data frame is

x<-data.frame(ID=c("abc/def","abc/def/ghi","abc","mno/pqr/st/ab"))

I want to split my column ID using "/" as the place to split. How can I do that without telling the code how many sub-columns. I could use nchar(gsub("[^/]","",x$ID)) to get how many "/" are in each row of the column, but could not use it to split ID in.

> read.table(text=as.character(x$ID), sep="/", fill=TRUE, as.is=TRUE)
   V1  V2  V3 V4
1 abc def
2 abc def ghi
3 abc
4 mno pqr  st ab

--

David Winsemius, MD
Alameda, CA, USA

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to