Dear R users,
I have a dataframe with one character field, and I would like to create two
new fields (columns) in my dataset, by spliting the existing character
field into two using an existing substring.
... something that in SAS I could solve e.g. combining substr(which I am
aware exist in
> x <- 'dfabcxy'
> strsplit(x, 'abc')
[[1]]
[1] "df" "xy"
>
On 10/28/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:
>
>
>
>
>
> Dear R users,
>
> I have a dataframe with one character field, and I would like to create
> two
> new fields (columns) in my dataset, by spliting the existing charact
see sub() and gsub(), but it won't be straightforward as somethink like
"string(dataframe)", ie you'll have to 1st treat the character object with
sub() or gsub() and 2d rebuils a dataframe.
hope this helps
Florence.
On 10/28/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:
>
>
>
>
>
> Dear R u
<[EMAIL PROTECTED]To: "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]>
om> cc:
r-help@stat.math.ethz.ch
is a list with three elements. But how
> to create the two vectors I need from here, that is
>
> ("dg","fgrt", "s") and ("rt","","uuu")
>
> (or how to get access to the substrings "rt" or "uuu").
n.be/~m0390867/dimitris.htm
- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc:
Sent: Friday, October 28, 2005 4:38 PM
Subject: Re: [R] splitting a character field in R
>
>
>
>
> Hi Jim,
>
> Thanks for your post, I was aware of st
[1] "dg" "rt"
>
> [[2]]
> [1] "fgrt"
>
> [[3]]
> [1] "s" "uuu"
>
> Which looks promissing, but here C is a list with three elements. But how
> to create the two vectors I need from here, that is
>
> ("dg","
On 28 Oct 2005, [EMAIL PROTECTED] wrote:
> A<-c(1,2,3)
> B<-c("dgabcrt","fgrtabc","sabcuuu")
> C<-strsplit(B,"abc")
> > C
> [[1]]
> [1] "dg" "rt"
>
> [[2]]
> [1] "fgrt"
>
> [[3]]
> [1] "s" "uuu"
>
> Which looks promissing, but here C is a list with three elements. But how
> to create the two
elements. But how
> > to create the two vectors I need from here, that is
> >
> > ("dg","fgrt", "s") and ("rt","","uuu")
> >
> > (or how to get access to the substrings "rt" or "uuu").
&g