[R] Odp: count - help
Petr PIKAL
petr.pikal at precheza.cz
Wed Jul 14 13:45:13 CEST 2010
Hi
You does not say much about what you really did. You probably want to
consult table or xtabs functions
> xtabs(~Petal.Width+Species, data=iris)
Species
Petal.Width setosa versicolor virginica
0.1 5 0 0
0.2 29 0 0
0.3 7 0 0
0.4 7 0 0
but it is only a guess based on what you say you wanted. Better to provide
some small example which anybody can repeat and explain what is your
desired output
Regards
Petr
r-help-bounces at r-project.org napsal dne 14.07.2010 13:29:35:
> 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 at ispa.pt
> barbarahcosta at gmail.com
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list