[R] Group by and add a constant value based on a condition dply

2021-05-26 Thread Elahe chalabi via R-help
Hi everyone, I have the following dataframe:        structure(list(Department = c("A", "A", "A", "A", "A", "A", "A",       "A", "B", "B", "B", "B", "B", "B", "B", "B"), Class = c(1L, 1L,      1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), Value = c(0L,      100L, 800L, 800L, 0L, 300L,

Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Gerrit Eichner
Hello, Elahe, you were, of course, supposed to insert my suggested code-snippet into you code and test it therein ... Regards -- Gerrit - Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@m

Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Elahe chalabi via R-help
Hello Gerit mutate(MinValue = min(Value[Value != 0]) )  or  mutate(MinValue = sort(unique(Value))[2]) only mutates one value which is 100, it doesnt mutate minimum Value != 0 per group by element On Tuesday, May 11, 2021, 01:26:49 PM GMT+2, Gerrit Eichner wrote: Homework? Try ma

Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Rui Barradas
Hello, This can be done by getting the min of Value[Value != 0]. In the code that follows I have named the expected output df2 and assigned the result to df3 and df4. library(dplyr) df3 <- df %>% group_by(Department,Class) %>% mutate(flag = Value != 0, MinValue = min(Value[flag]) ) %

Re: [R] Group by and duplicate a value/dplyr

2021-05-11 Thread Gerrit Eichner
Homework? Try maybe mutate(MinValue = min(Value[Value != 0]) ) or mutate(MinValue = sort(unique(Value))[2]) Hth -- Gerrit - Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eich...@math.uni-gie

[R] Group by and duplicate a value/dplyr

2021-05-11 Thread Elahe chalabi via R-help
Hi all, I have the following data frame  dput(df)     structure(list(Department = c("A", "A", "A", "A", "A", "A", "A",  "A", "B", "B", "B", "B", "B", "B", "B", "B"), Class = c(1L, 1L,  1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), Value = c(0L,  100L, 800L, 800L, 0L, 300L, 1200L, 1200

Re: [R] group by rows

2016-03-09 Thread Jim Lemon
Hi carol, You could use the "I" function, which will just return what you pass to it. Jim On Thu, Mar 10, 2016 at 12:28 AM, carol white via R-help wrote: > What should be FUN in aggregate as no function like mean, sum etc will be > applied > Carol > > On Wednesday, March 9, 2016 1:59 PM, S

Re: [R] group by rows

2016-03-09 Thread Sarah Goslee
On Wed, Mar 9, 2016 at 8:28 AM, carol white wrote: > What should be FUN in aggregate as no function like mean, sum etc will be > applied I have no idea, since you haven't told us what you want the results to look like. > Carol > > > On Wednesday, March 9, 2016 1:59 PM, Sarah Goslee > wrote: >

Re: [R] group by rows

2016-03-09 Thread PIKAL Petr
gt; From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of carol > white via R-help > Sent: Wednesday, March 09, 2016 2:28 PM > To: Sarah Goslee > Cc: R-help Help > Subject: Re: [R] group by rows > > What should be FUN in aggregate as no function like mean, sum e

Re: [R] group by rows

2016-03-09 Thread S Ellison
> How is it possible to group rows of a matrix or a data frame by the same > values > of the first column? If you mean _group_ as in SQL GROUP BY, use aggregate() with a count or summary statistic. If you mean _sort_, just to get similar values close together, use order() For example, to sort

Re: [R] group by rows

2016-03-09 Thread carol white via R-help
What should be FUN in aggregate as no function like mean, sum etc will be applied Carol On Wednesday, March 9, 2016 1:59 PM, Sarah Goslee wrote: Possibly aggregate(), but you posted in HTML so your data were mangled. Please use dput(), post in plain text, and try to explain more clear

Re: [R] group by rows

2016-03-09 Thread Sarah Goslee
Possibly aggregate(), but you posted in HTML so your data were mangled. Please use dput(), post in plain text, and try to explain more clearly what you want the result to look like. Sarah On Wed, Mar 9, 2016 at 7:09 AM, carol white via R-help wrote: > How is it possible to group rows of a matri

[R] group by rows

2016-03-09 Thread carol white via R-help
How is it possible to group rows of a matrix or a data frame by the same values of the first column? 1 14331 453452 653 3762 45 1 1433,453452 45, 653 376 Thanks Carol [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] group by function

2015-11-07 Thread Ragia Ibrahim
many thanks for replying, yes I am kindly accept my pardon, I mistaken the rows from each other many thanks I will read them. Ragia  > Date: Sat, 7 Nov 2015 07:48:36 -0800 > Subject: Re: [R] group by function > From: bgunter.4...@gmail.com &

Re: [R] group by function

2015-11-07 Thread Bert Gunter
?? Row 4 has i = 2 and Measure_id =4 and therefore has value divided by the max of all values with that i and Measure_id, which is 1. Row 7 has i =2 and Measure_id =2, and so is divided by the max value in all rows with those values of i and Measure_id, which is 2. etc. So either you do not unders

[R] group by function

2015-11-07 Thread Ragia Ibrahim
Dear group, kindly, I have the following data frame structure(c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1.5, 2, 1, 0, 2, 2, 1.5, 0, 0, 1, 1, 2, 0, 1, 2), .Dim = c(15L, 3L), .Dimnames = list( NULL, c("i", "Measure_id", "value"))) it has 3 c

Re: [R] group by and merge two dataframes

2014-05-09 Thread Massimo Bressan
yes thanks, that's correct! here a slight variation inspired by your solution: a cartesian product restricted to non duplicated records to get the logical vector i to be used in the next natural join i<-!duplicated(merge(df1$id,df1$item, by=NULL)) merge(df1[i,],df2) thanks Il 08/05/2014 18:

Re: [R] group by and merge two dataframes

2014-05-08 Thread arun
Hi, May be: indx <- !duplicated(as.character(interaction(df1[,-3]))) merge(df1[indx,],df2) A.K. On Thursday, May 8, 2014 12:34 PM, Massimo Bressan wrote: yes, thank you for all your replies, they worked out correctly indeed... ...but because of my fault, by then working on my real data I ful

Re: [R] group by and merge two dataframes

2014-05-08 Thread Massimo Bressan
yes, thank you for all your replies, they worked out correctly indeed... ...but because of my fault, by then working on my real data I fully realised that I should have mentioned something that is changing (quite a lot, in fact) the terms of the problem... please would you consider the follow

Re: [R] group by and merge two dataframes

2014-05-08 Thread arun
Hi, May be this helps:  merge(unique(df1),df2) A.K. On Thursday, May 8, 2014 5:46 AM, Massimo Bressan wrote: given this "bare bone" example: df1 <- data.frame(id=rep(1:3,each=2), item=c(rep("A",2), rep("B",2), rep("C",2))) df2 <- data.frame(id=c(1,2,3), who=c("tizio","caio","sempronio"))

Re: [R] group by and merge two dataframes

2014-05-08 Thread Rui Barradas
Hello, There are some alternatives without using sqldf or another package. 1. tmp2 <- aggregate(item ~ id, data = df1, FUN = unique) Then merge() like you've done. 2. tmp3 <- merge(df1, df2) tmp3[!duplicated(tmp3), ] Hope this helps, Rui Barradas Em 08-05-2014 10:44, Massimo Bressan escr

[R] group by and merge two dataframes

2014-05-08 Thread Massimo Bressan
given this "bare bone" example: df1 <- data.frame(id=rep(1:3,each=2), item=c(rep("A",2), rep("B",2), rep("C",2))) df2 <- data.frame(id=c(1,2,3), who=c("tizio","caio","sempronio")) I need to group the first dataframe "df1" by "id" and then merge with the second dataframe "df2" (again by "id")

Re: [R] Group by a data frame with multiple columns

2013-08-03 Thread arun
entical(datTest2,as.data.frame(dtTest2)) #[1] TRUE A.K. - Original Message - From: Michael Liaw To: r-help@r-project.org Cc: Sent: Saturday, August 3, 2013 8:11 PM Subject: [R] Group by a data frame with multiple columns Hi I'm trying to manipulate a data frame (that has about 10

[R] Group by a data frame with multiple columns

2013-08-03 Thread Michael Liaw
Hi I'm trying to manipulate a data frame (that has about 10 million rows) rows by "grouping" it with multiple columns. For example, say the data set looks like: Area Sex Year y Bob F 2011 1 Bob F 2011 2 Bob F 2012 3 Bob M 2012 3 Bob M 2012 2 Fred F 2011 1 Fr

Re: [R] Group by multiple variables

2011-05-30 Thread Sebastian P. Luque
On Mon, 30 May 2011 16:47:45 -0500, "Mendolia, Franco" wrote: > Hello, I would like to create a group variable that is based on the > values of three variables: > For example, >> dat <- data.frame(A=c(1,1,1,1,1,2,2,2,2,2), > B=c(1,1,1,5,5,5,9,9,9,9), > C=c(1,1,1,1,1,2,2,7,7,

Re: [R] Group by multiple variables

2011-05-30 Thread baptiste auguie
Hi, There are probably much better ways, but try this transform(dat, group = as.numeric(factor(paste(A,B,C, sep="" HTH, baptiste On 31 May 2011 09:47, Mendolia, Franco wrote: > Hello, > > I would like to create a group variable that is based on the values of three > variables: > > For ex

[R] Group by multiple variables

2011-05-30 Thread Mendolia, Franco
Hello, I would like to create a group variable that is based on the values of three variables: For example, > dat <- data.frame(A=c(1,1,1,1,1,2,2,2,2,2), B=c(1,1,1,5,5,5,9,9,9,9), C=c(1,1,1,1,1,2,2,7,7,7)) > dat A B C 1 1 1 1 2 1 1 1 3 1 1 1 4

Re: [R] group by in data.frame

2011-02-25 Thread zem
ok, i have it - match() 10x all again! :) -- View this message in context: http://r.789695.n4.nabble.com/group-by-in-data-frame-tp3324240p3325269.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list http

Re: [R] group by in data.frame

2011-02-25 Thread zem
hi guys, many many thanks for all the solutions! :-D they are working great! i have another "little" question: i would like to save these groups in a new column with serial number like the solution from David, but wit integer values: 1,2,3... i do this allready but with my 1. solution and there

Re: [R] group by in data.frame

2011-02-25 Thread Dennis Murphy
Hi: Here's another way: c1<-c(1,2,3,2,2,3,1,2,2,2) c2<-c(5,6,7,7,5,7,5,7,6,6) c3<-rnorm(10) x <- data.frame(c1 = factor(c1), c2 = factor(c2), c3) x <- transform(x, mean = ave(c3, c1, c2, FUN = mean)) Yet another with function ddply() in package plyr: ddply(x, .(c1, c2), transform, mean = mean(c3

Re: [R] group by in data.frame

2011-02-25 Thread David Winsemius
On Feb 25, 2011, at 10:14 AM, zem wrote: Yeah, you are right i want to post an short example what i want to do .. and in the meantime i solved the problem ... but here is: i have something like this dataframe: c1<-c(1,2,3,2,2,3,1,2,2,2) c2<-c(5,6,7,7,5,7,5,7,6,6) c3<-rnorm(10) x<-cbind(c1,c

Re: [R] group by in data.frame

2011-02-25 Thread Ivan Calandra
Ok, now I think I've understood, but I'm not sure since I think that my ave() solution does work. Although, I though you have several numerical variables and 1 factor; it is the opposite but it is still possible: c3_mean <- ave(x[,3], list(x[,1],x[,2]), FUN=mean) #note that values are differe

Re: [R] group by in data.frame

2011-02-25 Thread zem
Yeah, you are right i want to post an short example what i want to do .. and in the meantime i solved the problem ... but here is: i have something like this dataframe: c1<-c(1,2,3,2,2,3,1,2,2,2) c2<-c(5,6,7,7,5,7,5,7,6,6) c3<-rnorm(10) x<-cbind(c1,c2,c3) > x c1 c2 c3 [1,] 1 5

Re: [R] group by in data.frame

2011-02-25 Thread zem
10x i solved it ... mein problem was that i had 2 column by them i have to group, i just "pasted" the values together so that at the end i have one column to group and then was easy ... here is the script that i used: http://tolstoy.newcastle.edu.au/R/help/06/07/30184.html Ivan thanks for the hel

Re: [R] group by in data.frame

2011-02-25 Thread zem
Hi Ivan, thanks for your replay! but the problem is there that the dataframe has 2 rows and ca. 2000 groups, but i dont have the column with the groupnames, because the groups are depending on 2 onother columns ... any other idea or i didnt understand waht are you posted ... :( -- View th

Re: [R] group by in data.frame

2011-02-25 Thread Ivan Calandra
Hi, I think ave() might do what you want: df <- data.frame(a=rep(c("this","that"),5), b1=rnorm(10), b2=rnorm(10)) ave(df[,2], df[,1], FUN=mean) For all columns, you could do that: d <- lapply(df[,2:3], FUN=function(x)ave(x,df[,1],FUN=mean)) df2 <- cbind(df, d) HTH, Ivan Le 2/25/2011 12:11, zem

[R] group by in data.frame

2011-02-25 Thread zem
Hi all, i have a little problem, and i think it is really simple to solve, but i dont know exactly how to. here is the "challange": i have a data.frame with n colum, i have to group 2 of them and calculate the mean value of the 3. one. so far so good, that was easy - i used aggregate function to

Re: [R] Group by

2010-03-11 Thread ManInMoon
My point is this: if we do temp<-tDates aggregate(DF[,c('V2', 'V3')], list(format(temp, "%H:%M:00")), FUN = sum) Does agrregate still know it's refering to DF$V1 - and if so- how? -- View this message in context: http://n4.nabble.com/Group-by-tp1588694p1589600.html Se

Re: [R] Group by

2010-03-11 Thread Henrique Dallazuanna
tDates assumes DF$V1, which is from DF object. On Thu, Mar 11, 2010 at 11:13 AM, ManInMoon wrote: > > Thank you > > In the "aggregate" how does it know which column to group? > > I know you give it tDates as the second argument, but it doesn't know that > is from DF - we could have put anything t

Re: [R] Group by

2010-03-11 Thread ManInMoon
Thank you In the "aggregate" how does it know which column to group? I know you give it tDates as the second argument, but it doesn't know that is from DF - we could have put anything there I think... -- View this message in context: http://n4.nabble.com/Group-by-tp1588694p1589005.html Sent fr

Re: [R] Group by

2010-03-11 Thread Linlin Yan
> DF V1 V2 V3 1 10:03:13 3.4 1002 2 10:03:14 5.6 1001 3 10:05:27 7.2 999 4 10:05:33 8.2 998 > DF2 <- t(sapply(split(DF[,-1], gsub('(.{5}).*', '\\1:00', DF$V1)), colSums)) > data.frame(V1 = rownames(DF2), DF2) V1 V2 V3 10:03:00 10:03:00 9.0 2003 10:05:00 10:05:00 15.

Re: [R] Group by

2010-03-11 Thread Henrique Dallazuanna
Try this: DF <- read.csv(textConnection("V1,V2,V3 10:03:13,3.4,1002 10:03:14,5.6,1001 10:05:27,7.2,999 10:05:33,8.2,998"), header = TRUE) tDates <- strptime(DF$V1, "%H:%M:%S") tDates[[2]] <- floor(strptime(DF$V1, "%H:%M:%S")[[2]] / 5) * 5 aggregate(DF[,c('V2', 'V3')], list(format(tDate

[R] Group by

2010-03-11 Thread ManInMoon
I have a matrix with a POSIXct as a numeric in the first column. I would like to create a new matrix that is "grouped by" my chosed time bars. i.e. So I would like to group by hour or day or 5 days, and have all my columns be summed or averaged or counted.. mydata: V1,V2,V3 10:03:13,3.4,1002 1

Re: [R] Group by in R

2009-04-14 Thread Paul Johnson
On Mon, Apr 13, 2009 at 8:56 AM, Nick Angelou wrote: > >> data >   X1 X2 X3 X4 > 1   1  2  2  1 > 2   1  1  2  2 > 3   1  1  2  2 > 4   2  2  1  2 > 5   1  1  2  2 > 6   2  2  1  2 > 7   1  1  2  1 > 8   2  2  1  2 > 9   1  2  1  1 > 10  1  1  2  2 > > sqldf("select X1, X2, X3, X4, count(*) CNT fr

Re: [R] Group by in R

2009-04-13 Thread Gabor Grothendieck
Assuming DF is your data frame try this: ftable(DF) In SQL you can get close with: sqldf("select X1, X2, X3, sum(X4 == 1) `X4=1`, sum(X4 == 2) `X4=2` from DF group by X1, X2, X3 order by X1, X2, X3") On Mon, Apr 13, 2009 at 9:56 AM, Nick Angelou wrote: > > > Gabor Grothendieck wrote: >> >> SQL

Re: [R] Group by in R

2009-04-13 Thread Nick Angelou
Gabor Grothendieck wrote: > > SQL has the order by clause. > Gabor, thanks for the suggestion. I thought about this but ORDER BY cannot create the tabular structure that I need. Here is more detail about my setting: f1, f2, f3 have unique triplets (each repeating a different number of times).

Re: [R] Group by in R

2009-04-13 Thread David Winsemius
On Apr 13, 2009, at 7:26 AM, Nick Angelou wrote: Thanks a lot, guys. Gabor's and Mike's suggestion worked. Duncan's did not do exactly what I expected (I guess it's the "paste" in Mike's that makes "table" work as I needed it). One more question - is there a convenient way to order the gro

Re: [R] Group by in R

2009-04-13 Thread Gabor Grothendieck
SQL has the order by clause. On Mon, Apr 13, 2009 at 7:26 AM, Nick Angelou wrote: > > Thanks a lot, guys. Gabor's and Mike's suggestion worked. Duncan's did not do > exactly what I expected (I guess it's the "paste" in Mike's that makes > "table" work as I needed it). > > One more question - is t

Re: [R] Group by in R

2009-04-13 Thread Nick Angelou
Thanks a lot, guys. Gabor's and Mike's suggestion worked. Duncan's did not do exactly what I expected (I guess it's the "paste" in Mike's that makes "table" work as I needed it). One more question - is there a convenient way to order the group by results as follows: As rows: the unique combinati

Re: [R] Group by in R

2009-04-13 Thread Peter Dalgaard
Mike Lawrence wrote: One way: g= paste(f1,f2,f3,f4) table(g) I'd go for g <- interaction(f1,f2,f3,f4, drop=TRUE) table(g) which is essentially the same thing. On Mon, Apr 13, 2009 at 7:33 AM, Nick Angelou wrote: Hi, I have the following table data: f1, f2, f3, f4. I want to compute t

Re: [R] Group by in R

2009-04-13 Thread Mike Lawrence
One way: g= paste(f1,f2,f3,f4) table(g) On Mon, Apr 13, 2009 at 7:33 AM, Nick Angelou wrote: > > Hi, > > I have the following table data: > > f1, f2, f3, f4. > > I want to compute the counts of unique combinations of f1-f4. In SQL I would > just write: > > SELECT COUNT(*) FROM GROUP BY f1, f2,

Re: [R] Group by in R

2009-04-13 Thread Gabor Grothendieck
You can use SQL commands directly on R data frames with the R sqldf package: See home page: http://sqldf.googlecode.com On Mon, Apr 13, 2009 at 6:33 AM, Nick Angelou wrote: > > Hi, > > I have the following table data: > > f1, f2, f3, f4. > > I want to compute the counts of unique combinations of

Re: [R] Group by in R

2009-04-13 Thread Duncan Murdoch
Nick Angelou wrote: Hi, I have the following table data: f1, f2, f3, f4. I want to compute the counts of unique combinations of f1-f4. In SQL I would just write: SELECT COUNT(*) FROM GROUP BY f1, f2, ..,f4. How to do this in R? table(f1,f2,f3,f4) will give you the counts. Other statistic

[R] Group by in R

2009-04-13 Thread Nick Angelou
Hi, I have the following table data: f1, f2, f3, f4. I want to compute the counts of unique combinations of f1-f4. In SQL I would just write: SELECT COUNT(*) FROM GROUP BY f1, f2, ..,f4. How to do this in R? Thanks, Nick -- View this message in context: http://www.nabble.com/Group-by-in-

Re: [R] group by-like statement for 2-row matrix

2009-04-08 Thread Hans-Henning Gabriel
Luc, Eik, Jorge, thanks to all of you! Nice to see how many different solutions there are for the same problem. :) Best Henning Am 07.04.2009 um 22:25 schrieb Jorge Ivan Velez: > > Dear Hans, > > Try also: > > x <- structure(c(2, 1, 2, 1, 3, 2, 4, 1, 4, 3, 4, 3, 5, 2, 5, 1, 6, > 1), .Dim

Re: [R] group by-like statement for 2-row matrix

2009-04-07 Thread Jorge Ivan Velez
Dear Hans, Try also: x <- structure(c(2, 1, 2, 1, 3, 2, 4, 1, 4, 3, 4, 3, 5, 2, 5, 1, 6, 1), .Dim = c(2L, 9L)) tapply(x[2,],x[1,],sum) #2 3 4 5 6 #2 2 7 3 1 HTH, Jorge On Tue, Apr 7, 2009 at 11:06 AM, Hans-Henning Gabriel < hanshenning.gabr...@gmail.com> wrote: > Hi, > > my problem is as foll

Re: [R] group by-like statement for 2-row matrix

2009-04-07 Thread rmailbox
bycols.df , FUN = sum, > keep.names = TRUE ) > sumbycols.df x y 1 2 2 2 3 2 3 4 7 4 5 3 5 6 1 > sumbyrows.df <- t ( sumbycols.df ) > sumbyrows.df 1 2 3 4 5 x 2 3 4 5 6 y 2 2 7 3 1 > - Original message - From: "Eik Vettorazzi" To: "Hans-Henning Ga

Re: [R] group by-like statement for 2-row matrix

2009-04-07 Thread Eik Vettorazzi
see ?aggregate m<-rbind(sample(2:6,9,replace=T),sample(1:3,9,replace=T)) aggregate(m[2,],by=list(m[1,]),sum) Hans-Henning Gabriel schrieb: Hi, my problem is as follows: I have a matrix of two rows like this: 2 2 3 4 4 4 5 5 6 1 1 2 1 3 3 2 1 1 Can I apply something like "group by" in sql? W

Re: [R] group by-like statement for 2-row matrix

2009-04-07 Thread Luc Villandre
Hi Henning, Although there might be a better way to do this, I'd suggest (with my.matrix being the matrix you provided): complete.vector = rep(my.matrix[1,],my.matrix[2,]) ; table(complete.vector) ; Is this what you're looking for? Cheers, Luc Hans-Henning Gabriel wrote: Hi, my problem i

[R] group by-like statement for 2-row matrix

2009-04-07 Thread Hans-Henning Gabriel
Hi, my problem is as follows: I have a matrix of two rows like this: 2 2 3 4 4 4 5 5 6 1 1 2 1 3 3 2 1 1 Can I apply something like "group by" in sql? What I want to achieve is the some of second row for each unique entry of first row: 2 -> 2 (=1+1) 3 -> 2 4 -> 7 (=1+3+3) 5 -> 3 (=2+1) 6 -

Re: [R] group by quantiles

2008-11-18 Thread Gabor Grothendieck
The gtools package has quantcut. On Tue, Nov 18, 2008 at 6:53 AM, Daniel Brewer <[EMAIL PROTECTED]> wrote: > Hello, > > I was just wondering whether there is a quick way to divide a vector of > data into four groups defined by the quantiles? > i.e. > 0-25% > 25-50% > 50-75% > 75-100% > > Many than

Re: [R] group by quantiles

2008-11-18 Thread Frank E Harrell Jr
Daniel Brewer wrote: Hello, I was just wondering whether there is a quick way to divide a vector of data into four groups defined by the quantiles? i.e. 0-25% 25-50% 50-75% 75-100% Many thanks Dan library(Hmisc) cut2(x, g=4) -- Frank E Harrell Jr Professor and Chair School of M

Re: [R] group by quantiles

2008-11-18 Thread Dimitris Rizopoulos
check at cut() and split(), e.g., x <- rnorm(100) qx <- quantile(x) ind <- cut(x, qx, include.lowest = TRUE) split(x, ind) I hope it helps. Best, Dimitris Daniel Brewer wrote: Hello, I was just wondering whether there is a quick way to divide a vector of data into four groups defined by the

[R] group by quantiles

2008-11-18 Thread Daniel Brewer
Hello, I was just wondering whether there is a quick way to divide a vector of data into four groups defined by the quantiles? i.e. 0-25% 25-50% 50-75% 75-100% Many thanks Dan -- ** Daniel Brewer, Ph.D. Institute of Cancer Research M

Re: [R] "group by" functionality in R

2008-10-01 Thread Henrique Dallazuanna
Try this also; xtabs(volume ~ day, data = x) On Wed, Oct 1, 2008 at 10:58 AM, Max Rausch <[EMAIL PROTECTED]> wrote: > I have a data frame with the following information > > day hourvolume > 1 2003-07-18 10 836700 > 2 2003-07-18 11 375000 > 3 2003-07-18 12

Re: [R] "group by" functionality in R

2008-10-01 Thread hadley wickham
On Wed, Oct 1, 2008 at 8:58 AM, Max Rausch <[EMAIL PROTECTED]> wrote: > I have a data frame with the following information > > day hourvolume > 1 2003-07-18 10 836700 > 2 2003-07-18 11 375000 > 3 2003-07-18 12 6 > 4 2003-07-188 102 > 5

Re: [R] "group by" functionality in R

2008-10-01 Thread John Kane
Two approaches ?aggregate or the reshape package aggregate(xx$volume, list(day=xx$day), sum) library(reshape) names(xx)[3] <- "value" cast(xx, day ~ ., sum) --- On Wed, 10/1/08, Max Rausch <[EMAIL PROTECTED]> wrote: > From: Max Rausch <[EMAIL PROTECTED]&

Re: [R] "group by" functionality in R

2008-10-01 Thread Gábor Csárdi
tapply(data$volume, data$day, sum) would do I think. But I haven't tried, was to lazy to type in some data, I'm sorry. Gabor On Wed, Oct 1, 2008 at 3:58 PM, Max Rausch <[EMAIL PROTECTED]> wrote: > I have a data frame with the following information > > day hourvolume > 1 2003

Re: [R] "group by" functionality in R

2008-10-01 Thread jim holtman
?aggregate day hour volume 1 2003-07-18 10 836700 2 2003-07-18 11 375000 3 2003-07-18 12 6 4 2003-07-188 102 5 2003-07-189 39 > aggregate(x$volume, list(x$day), sum) Group.1 x 1 2003-07-18 2681700 On Wed, Oct 1, 2008 at 9:58 AM, Max Rausch <[EM

[R] "group by" functionality in R

2008-10-01 Thread Max Rausch
I have a data frame with the following information day hourvolume 1 2003-07-18 10 836700 2 2003-07-18 11 375000 3 2003-07-18 12 6 4 2003-07-188 102 5 2003-07-189 39 I have been trying create a new data frame with the