[R] ?nchar ?strsplit

Bert Gunter gunter.berton at gene.com
Mon Aug 27 22:00:14 CEST 2012


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

-- Bert

On Mon, Aug 27, 2012 at 12:58 PM, Bert Gunter <bgunter at gene.com> wrote:
> (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



-- 

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




More information about the R-help mailing list