Re: [R] create data set from selection of rows

2011-03-17 Thread Dennis Murphy
Using the summarise function in package plyr is one way; taking df to be your data frame with variable names V1-V4, library(plyr) summarise(subset(df, V3 == 'text3'), sum = sum(V4)) sum 1 134 Another is to use the data.table package: library(data.table) dt <- data.table(df) dt[V3 == 'text3', s

Re: [R] create data set from selection of rows

2011-03-17 Thread jim holtman
Is this what you want: > x V1 V2V3 V4 1 text1 23 text2 45 2 text1 23 text3 78 3 text1 23 text3 56 4 text1 23 text2 45 > str(x) 'data.frame': 4 obs. of 4 variables: $ V1: Factor w/ 1 level "text1": 1 1 1 1 $ V2: int 23 23 23 23 $ V3: Factor w/ 2 levels "text2","text3": 1 2 2 1 $ V4

Re: [R] create data set from selection of rows

2011-03-17 Thread e-letter
On 15/03/2011, Francisco Gochez wrote: > Hi, > > What you are after is: > > datasubset <- dataset[ dataset[,3] == "text3", ] Thank you. For the set text1,23,text2,45 text1,23,text3,78 text1,23,text3,56 text1,23,text2,45 Is it possible to write a function that selects rows containing 'text3' and

Re: [R] create data set from selection of rows

2011-03-15 Thread Francisco Gochez
Hi, What you are after is: datasubset <- dataset[ dataset[,3] == "text3", ] Equivalently, you can use: datasubset <- subset(dataset, subset = dataset[,3] == "text3") HTH, Francisco On Tue, Mar 15, 2011 at 3:09 PM, e-letter wrote: > Readers, > > For a data set: > > text1,23,text2,45 > text1

Re: [R] create data set from selection of rows

2011-03-15 Thread Mohamed Lajnef
Hi, Le 15/03/11 16:09, e-letter a écrit : > Readers, > > For a data set: > > text1,23,text2,45 > text1,23,text3,78 > text1,23,text3,56 > text1,23,text2,45 > > The following command was entered: > > datasubset<-data.frame(dataset[,3]=="text3") datasubset<-subset(dataset,dataset[,3]=="text3") > The

Re: [R] create data set from selection of rows

2011-03-15 Thread nblarson
Try using which() Something like data.frame(dataset[which(dataset[,3]=="text3"),]) e-letter wrote: > > Readers, > > For a data set: > > text1,23,text2,45 > text1,23,text3,78 > text1,23,text3,56 > text1,23,text2,45 > > The following command was entered: > > datasubset<-data.frame(dataset[,3]

[R] create data set from selection of rows

2011-03-15 Thread e-letter
Readers, For a data set: text1,23,text2,45 text1,23,text3,78 text1,23,text3,56 text1,23,text2,45 The following command was entered: datasubset<-data.frame(dataset[,3]=="text3") The result of datasubset is TRUE TRUE The required result is text1,23,text3,78 text1,23,text3,56 What is the co