[R] Working with data-frame

2014-11-09 Thread Christofer Bogaso
Hi again, Let say, I have following data frame: Dat - structure(list(A1 = structure(c(3L, 3L, 1L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L, 1L, 1L, 3L, 3L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 2L, 3L, 1L, 1L, 3L), .Label = c(a, b, c), class = factor), A2 = c(2, 3, 2, 1, 3, 3, 2, 2, 3, 1, 3, 1, 3,

Re: [R] Working with data-frame

2014-11-09 Thread Bert Gunter
Christopher: If I understand correctly, see ?ave, or ?tapply, depending on what form you want to be returned. The trick is to first paste the columns together on whose unique you want to split to form a singtl factor. e.g. of the form lapply(split(yourcolumn,paste0(...)),FUN= sum) However, the

Re: [R] Working with data-frame

2014-11-09 Thread William Dunlap
I tried with spilt() function. However it looks to me that, it can split a data-frame w.r.t. only one column. (I assume you you meant 'split', not 'spilt'.) You did not show what you tried, but the following splits Dat by its A1 and A2 columns (creating a list of data.frames): split(Dat,

Re: [R] Working with data-frame

2014-11-09 Thread Jeff Newmiller
... so... #1 ... flexible syntax for split-apply-combine, not very efficient for large data library(plyr) ddply(Dat,c(A1, A2), function(DF){data.frame(C1=sum(DF$C1))}) #2 ... compatible with large data on disk library(sqldf) sqldf(select A1,A2,sum(C1) as C1 from Dat group by A1, A2) #3 ...