[R] regex expression to select row or column

jim holtman jholtman at gmail.com
Sat Jul 25 10:13:21 CEST 2009


It it not entirely clear what the format of your data is. If you have
a dataframe that you would like to separate into several different one
based on the value in a column, then something like this will work:

df.list <- split(yourDF, yourDF$column)

This will create a list of dataframes, split according to the contents
of "column".

On Fri, Jul 24, 2009 at 9:20 PM, Junqian Gordon Xu<xjqian at gmail.com> wrote:
> I have a multidimensional data which looks like the following:
>
>       "S1-a" "S2-b" "S3-c" "S4-d" "S5-a" "S6-b" "S7-c" "S8-d"
> "T1-A"
> "T1-B"
> "T1-C"
> "T1-D"
> "T2-A"
> "T2-B"
> "T2-C"
> "T2-D"
>
> I read it from csv file and would like to have 16 separate data frames like
> this
>
>     "S1-a" "S2-a"     "S1-b" "S2-b"     "S1-c" "S2-c"    "S1-d" "S2-d"
> "T1-A"            "T1-A"            "T1-A"            "T1-A"
> "T2-A"            "T2-A"            "T2-A"            "T2-A"
>
>     "S1-b" "S2-b"   ...
> "T1-B"               ...
> "T1-B"               ...
>
> ...
> ...
>
> One way is to use loops to cycle through, but I think it's even simpler to
> use regex expression to separate them since "abcd" and "ABCD" are unique
> strings in the table. Does anybody have any pointer on how to do this?
>
> Thanks
> Gordon
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list