Re: [R] Split data frame based on Class

2009-05-18 Thread Kushantha Perera
Try split()!
?split

e.g
> a
   var1 var2 var3
1 a14
2 a25
3 a36
4 b47
5 b58
6 a69
7 b7   NA
8 c82
9 c95
10b34
11a24
12a14
13c23
14c54
> split(a,a["var1"])
$a
   var1 var2 var3
1 a14
2 a25
3 a36
6 a69
11a24
12a14

$b
   var1 var2 var3
4 b47
5 b58
7 b7   NA
10b34

$c
   var1 var2 var3
8 c82
9 c95
13c23
14c54

Cheers!
Kushantha


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Chris Arthur
Sent: Monday, May 18, 2009 4:54 PM
To: r-help@r-project.org
Subject: [R] Split data frame based on Class

Each row of my data frame is assigned to a class (eg country). Can you 
suggest how I break apart the data frame so that I create new data 
frames for each class

eg

If Class = "US" put in new dataframe dataUS

Thanks in advance for your help

Chris

__
R-help@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.
This e-mail may contain confidential and/or privileged i...{{dropped:10}}

__
R-help@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.


Re: [R] Split data frame based on Class

2009-05-18 Thread jim holtman
?split

new.df <- split(old.df, old.df$Class)

will create a list of dataframes split by Class

On Mon, May 18, 2009 at 7:23 AM, Chris Arthur wrote:

> Each row of my data frame is assigned to a class (eg country). Can you
> suggest how I break apart the data frame so that I create new data frames
> for each class
>
> eg
>
> If Class = "US" put in new dataframe dataUS
>
> Thanks in advance for your help
>
> Chris
>
> __
> R-help@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?

[[alternative HTML version deleted]]

__
R-help@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.


[R] Split data frame based on Class

2009-05-18 Thread Chris Arthur
Each row of my data frame is assigned to a class (eg country). Can you 
suggest how I break apart the data frame so that I create new data 
frames for each class


eg

If Class = "US" put in new dataframe dataUS

Thanks in advance for your help

Chris

__
R-help@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.