Re: [R] splitting a character field in R

From: <>
Date: Sat 29 Oct 2005 - 00:38:34 EST

Hi Jim,

Thanks for your post, I was aware of strsplit, but really could not find out how i could use it.

I tried like in your example ...


> C

[1] "dg" "rt"

[1] "fgrt"

[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","fgrt", "s") and ("rt","","uuu")

(or how to get access to the substrings "rt" or "uuu").



                      jim holtman                                                                                                
                      <jholtman@gmail.c        To:       "" <>         
                      om>                      cc:                                                
                                               Subject:  Re: [R] splitting a character field in R                                
                      28.10.2005 16:00                                                                                           

> x <- 'dfabcxy'
> strsplit(x, 'abc')
[1] "df" "xy"


On 10/28/05, < > 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
      field into two using an existing substring.

      ... something that in SAS I could solve e.g. combining substr(which I
      aware exist in R) and "index" for determining the position of the
      within the string.
      e.g. if my dataframe is ...
      A     B
      1     dgabcrt
      2     fgrtabc
      3     sabcuuu

      Then by splitting by substring "abc" I would get ...

      A     B           B1    B2
      1     dgabcrt     dg    rt
      2     fgrtabc     fgrt
      3     sabcuuu     s     uuu

      Do you know how to do this basic string(dataframe) manipulation in R



      ______________________________________________ mailing list
      PLEASE do read the posting guide!

Jim Holtman
Cincinnati, OH
+1 513 247 0281

What the problem you are trying to solve?

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Sat Oct 29 00:45:38 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:52 EST