Message-ID: <005001cd848f$8a6e3300$9f4a9900$@edu>
Date: 2012-08-27T20:07:09Z
From: David L Carlson
Subject: ?nchar ?strsplit
In-Reply-To: <1346092830.97450.YahooMailNeo@web125205.mail.ne1.yahoo.com>
Splitting is easy:
strsplit(as.character(x$ID), "/")
That produces a list with four elements, each of which is a character
vector. R does not have a representation for "sub-columns" so you will have
to be clearer about how you want to represent the data and what you are
planning to do with it.
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Sapana Lohani
> Sent: Monday, August 27, 2012 1:41 PM
> To: R help
> Subject: [R] ?nchar ?strsplit
>
> 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]]