Re: [R] Splitting Data Frame into Two Based on Source Array

2008-09-09 Thread Adam D. I. Kramer

data_main[ match(src,data_main$V1), ]

and the compliment of src (call it srcc)

data_main[ match(srcc,data_main$V1), ]

...this only works so long as there is only one occurrance of each item in
V1 in V1.

--Adam

On Tue, 9 Sep 2008, Gundala Viswanath wrote:


Dear all,

Suppose I have this data frame:



data_main

  V1  V2
foo13.1
bar   12.0
qux   10.4
cho  20.33
pox   8.21

And I want to split the data into two parts
first part are the one contain in the source array:


src

[1] bar pox

and the other one the complement.

In the end we hope to get this two dataframes:


data_child1

V1 V2
bar   13.1
pox   8.21

and


data_child2_complement

foo 13.1
qux 10.4
cho 20.33

Is there a compact way to do it in R?




- Gundala Viswanath
Jakarta - Indonesia

__
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-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] Splitting Data Frame into Two Based on Source Array

2008-09-08 Thread Gundala Viswanath
Dear all,

Suppose I have this data frame:


 data_main
   V1  V2
foo13.1
bar   12.0
qux   10.4
cho  20.33
pox   8.21

And I want to split the data into two parts
first part are the one contain in the source array:

 src
[1] bar pox

and the other one the complement.

In the end we hope to get this two dataframes:

 data_child1
 V1 V2
bar   13.1
pox   8.21

and

 data_child2_complement
foo 13.1
qux 10.4
cho 20.33

Is there a compact way to do it in R?




- Gundala Viswanath
Jakarta - Indonesia

__
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] Splitting Data Frame into Two Based on Source Array

2008-09-08 Thread Jorge Ivan Velez
Dear Gundala,
Try this:

# Data set
data_main=read.table(textConnection(V1  V2
foo13.1
bar   12.0
qux   10.4
cho  20.33
pox   8.21),header=TRUE)
attach(data_main)
closeAllConnections()


# Criteria
src=c('bar','pox')

# data_child1
data_main[V1%in%src,]

# data_child2_complement
data_main[!V1%in%src,]


See ?%in% for more information.


HTH,


Jorge



On Mon, Sep 8, 2008 at 11:17 PM, Gundala Viswanath [EMAIL PROTECTED]wrote:

 Dear all,

 Suppose I have this data frame:


  data_main
   V1  V2
 foo13.1
 bar   12.0
 qux   10.4
 cho  20.33
 pox   8.21

 And I want to split the data into two parts
 first part are the one contain in the source array:

  src
 [1] bar pox

 and the other one the complement.

 In the end we hope to get this two dataframes:

  data_child1
 V1 V2
 bar   13.1
 pox   8.21

 and

  data_child2_complement
 foo 13.1
 qux 10.4
 cho 20.33

 Is there a compact way to do it in R?




 - Gundala Viswanath
 Jakarta - Indonesia

 __
 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.


[[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.


Re: [R] Splitting Data Frame into Two Based on Source Array

2008-09-08 Thread Gabor Grothendieck
Try this which gives a list of two data frames:

split(data_main, data_main$V1 %in% c(foo, bar))


On Mon, Sep 8, 2008 at 11:17 PM, Gundala Viswanath [EMAIL PROTECTED] wrote:
 Dear all,

 Suppose I have this data frame:


 data_main
   V1  V2
 foo13.1
 bar   12.0
 qux   10.4
 cho  20.33
 pox   8.21

 And I want to split the data into two parts
 first part are the one contain in the source array:

 src
 [1] bar pox

 and the other one the complement.

 In the end we hope to get this two dataframes:

 data_child1
 V1 V2
 bar   13.1
 pox   8.21

 and

 data_child2_complement
 foo 13.1
 qux 10.4
 cho 20.33

 Is there a compact way to do it in R?




 - Gundala Viswanath
 Jakarta - Indonesia

 __
 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-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.