Hi, I have a data frame with several factors and I want to count the occurrences of an event resulting from an interaction of some factors. I tried to do several tables (and then converting to d.f and then merge them by one factor and the freq Tab1 <- merge (BPorAmost,BPorSector,by=c('Sample','Freq')) Tab1 <- merge (Tab1,BPorDist,by=c('Sample','Freq')) Tab1 <- merge (Tab1,BPorProf,by=c('Sample','Freq')) But I have lots of NAs because I can have a interaction between sample and freq different for each factor: to the same sample and the same freq I can have 2 or more different factors. And also I don't need those lots of zeros. I'd only need a table as excell does with pivot table and summarize data as count I also tried to make a F.Aggregate.DFrame(df [,2],df[,c(1,3,4)],length) but it doesn't work. Do you have some suggestions? I'd really like to learn doing it in R and not having to shift to excell! Thanks a lot, Cheers, Barbara -- Bárbara H. Costa Marine Biologist Researcher SCIAENA - Marine Sciences and Cooperation www.sciaena.org ISPA | http://www.ispa.pt/ui/uie/index.asp BIOMARES | http://www.ccmar.ualg.pt/biomares/ MSI-UCSB | http://www.msi.ucsb.edu/ bcosta@ispa.pt barbarahcosta@gmail.com [[alternative HTML version deleted]]
Hi, I have a data frame with several factors and I want to count the occurrences of an event resulting from an interaction of some factors. I tried to do several tables (and then converting to d.f and then merge them by one factor and the freq Tab1 <- merge (BPorAmost,BPorSector,by=c('Sample','Freq')) Tab1 <- merge (Tab1,BPorDist,by=c('Sample','Freq')) Tab1 <- merge (Tab1,BPorProf,by=c('Sample','Freq')) But I have lots of NAs because I can have a interaction between sample and freq different for each factor: to the same sample and the same freq I can have 2 or more different factors. And also I don't need those lots of zeros. I'd only need a table as excell does with pivot table and summarize data as count. I also tried to make an aggregation: e.g. F.Aggregate.DFrame(df [,2],df[,c(1,3,4)],length) but it doesn't work with length - results are all 1. Do you have some suggestions? I'd really like to learn doing it in R and not having to shift to excell! Thanks a lot, Cheers, Barbara -- Bárbara H. Costa Marine Biologist Researcher SCIAENA - Marine Sciences and Cooperation www.sciaena.org ISPA | http://www.ispa.pt/ui/uie/index.asp BIOMARES | http://www.ccmar.ualg.pt/biomares/ MSI-UCSB | http://www.msi.ucsb.edu/ bcosta@ispa.pt barbarahcosta@gmail.com [[alternative HTML version deleted]]
barbara horta e costa wrote:> > I have a data frame with several factors and I want to count the > occurrences > of an event resulting from an interaction of some factors. > > I'd only need a table as excel does with pivot table and summarize data as > count >"Only" what pivot tables does: Pivot tables are one of the best features of Excel, and it's not always that easy in R. Hadley Wickham who has written the "reshape" package, admitted that he tried to mimic pivot tables in R; the fact that the has not been ripped into piece because of this confession tells a lot. Anyway: give package reshape a try; it comes with a nice tutorial. And if you have more questions, try to construct a very simple example (3 lines!) that runs out of the box and shows your problem. I assume that merge (which does something like SQL join) is not what you need, but I am not sure Dieter -- View this message in context: http://r.789695.n4.nabble.com/count-help-tp2288571p2288764.html Sent from the R help mailing list archive at Nabble.com.