[R] keep the row indexes/names when do aggregate

2008-09-24 Thread zhihuali
Hi, R-users, If I have a data frame like this: >x<-data.frame(g=c("g1","g2","g1","g1","g2"),v=c(1,7,3,2,8)) g v 1 g1 1 2 g2 7 3 g1 3 4 g1 2 5 g2 8 It contains two groups, g1 and g2. Now for each group I want the max v: > aggregate(x$v,list(g=x$g),max) g x 1 g1 3 2 g2 8 Beautiful. But wh

Re: [R] sort a data matrix by all the values and keep the names

2008-09-22 Thread zhihuali
print(str(temp)) > > sortedx <- temp[order(temp$values),] > print(sortedx) > > > > On Mon, Sep 22, 2008 at 7:54 PM, zhihuali wrote: > > > Dear all, > > > > If I have a data frame x<-data.frame(x1=c(1,7),x2=c(4,6),x3=c(8,2)): > >x1 x2 x3 &

[R] sort a data matrix by all the values and keep the names

2008-09-22 Thread zhihuali
Dear all, If I have a data frame x<-data.frame(x1=c(1,7),x2=c(4,6),x3=c(8,2)): x1 x2 x3 1 4 8 7 6 2 I want to sort the whole data and get this: x1 1 x3 2 x2 4 x2 6 x1 7 x3 8 If I do sort(X), R reports: Error in order(list(x1 = c(1, 7), x2 = c(4, 6), x3 = c(8, 2)),

[R] how to use a function in aggregate which accepts matrix and outputs matrix?

2008-04-17 Thread zhihuali
Dear netters, suppose I have a matrix X [1,] 'c1' 'r6' '150'[2,] 'c1' 'r4' '70'[3,] 'c1' 'r2' '20'[4,] 'c1' 'r5' '90'[5,] 'c2' 'r2' '20'[6,] 'c3' 'r1' '10'I want to apply some funciton to groups of rows by the first column.If the function is just to calculate the average X[,3], it will be

[R] locate the rows in a dataframe with some criteria

2008-03-07 Thread zhihuali
Hi, netters, This is probably a rookie question but I couldn't find the answer after hours of searching and trying. Suppose there'a a dataframe M: x y 10 A 13 B 8 A 11 A I want to locate the rows where x >=10 and y="A". I know how to do it to vectors by using which, but how t

Re: [R] Comparison of aggregate in R and group by in mysql

2008-01-26 Thread zhihuali
It is having to 'split' the > data into the groups and then summarize. Maybe you should use a > database with this combination of data. > > 2008/1/26 zhihuali <[EMAIL PROTECTED]>: > > > > I repeated your experiment: > > > n <- 100 > > > x

Re: [R] Comparison of aggregate in R and group by in mysql

2008-01-26 Thread zhihuali
x$B, x$C), mean)) >user system elapsed >2.650.343.00 > > > > On Jan 26, 2008 6:45 PM, zhihuali <[EMAIL PROTECTED]> wrote: > > > > Hi, netters, > > > > First of all, thanks a lot for all the prompt replies to my earlier > > qu

[R] Comparison of aggregate in R and group by in mysql

2008-01-26 Thread zhihuali
Hi, netters, First of all, thanks a lot for all the prompt replies to my earlier question about "merging" data frames in R. Actually that's an equivalence to the "join" clause in mysql. Now I have another question. Suppose I have a data frame X with lots of columns/variables: Name, Age,Group,

[R] An R clause to bind dataframes under certain contions

2008-01-26 Thread zhihuali
Hi netters, Suppose I have two data frames X and Y. X has three colnames A, B and C. Y has three colnames A,B and D. I want to combine them into one matrix, joining the rows having the same A and B values (X$A==Y$A and X$B = Y$B). So the resulting dataframe has four variables/columns: A,B,C an