Skip to content
Back to formatted view

Raw Message

Message-ID: <CACk-te3EoB1V_qc4sv4KVFPdashER7BcWmxQznDX-_kvrzZgQQ@mail.gmail.com>
Date: 2012-08-27T19:58:47Z
From: Bert Gunter
Subject: ?nchar ?strsplit
In-Reply-To: <1346092830.97450.YahooMailNeo@web125205.mail.ne1.yahoo.com>

(Re-)read ?strsplit. You do not have to tell the code how many columns ... etc.
And the split isn't into sub columns.

y <- as.character(x[[1]] ## You need a character vector argument
strsplit(y,"/") ## works

-- Bert

On Mon, Aug 27, 2012 at 11:40 AM, Sapana Lohani <lohani.sapana at ymail.com> 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.
>
> Thanks
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at 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.
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm