Re: [R] Crosstabulation with a frequency variable

2015-08-13 Thread Bert Gunter
Yes and yes. To be clear, 1. sum() is better. 2. xtabs is better (I just forgot about it and didn't bother to search). Maybe the best answer is in fact, ??crosstabulation which would have brought up xtabs(). So the moral is (to the OP), learn how to search before posting. Cheers, Bert Bert Gu

Re: [R] Crosstabulation with a frequency variable

2015-08-13 Thread peter dalgaard
> On 13 Aug 2015, at 16:24 , Bert Gunter wrote: > > Well, just using base R, ... > >> with(mydata,tapply(freq,list(var1,var2),I)) > 0 1 > 0 11 12 > 1 13 14 If you insist on avoiding the stats package... However, I'd use sum() rather than I() to get an xtabs() workalike. -pd > > > Cheer

Re: [R] Crosstabulation with a frequency variable

2015-08-13 Thread Bert Gunter
Well, just using base R, ... > with(mydata,tapply(freq,list(var1,var2),I)) 0 1 0 11 12 1 13 14 Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Thu, Aug 13, 2015 at 6:39 AM, Sarah Goslee wro

Re: [R] Crosstabulation with a frequency variable

2015-08-13 Thread Marc Schwartz
Hi, As Sarah noted, there are a variety of ways in R to accomplish this, such as: DF <- data.frame(var1 = c(0, 0, 1, 1), var2 = c(0, 1, 0, 1), freq = c(11, 12, 13, 14)) > xtabs(freq ~ var1 + var2, data = DF) var2 var1 0 1 0 11 12 1 13 14 See ?xtabs Regards, Marc Schwartz > On

Re: [R] Crosstabulation with a frequency variable

2015-08-13 Thread Sarah Goslee
Hi, There are lots of ways to do it in base R, but a long time ago I got frustrated and wrote a crosstab function that did exactly what I wanted: library(ecodist) mydata <- data.frame(var1=c(0,0,1,1),var2=c(0,1,0,1),freq=c(11,12,13,14)) crosstab(var1, var2, freq, data=mydata) 0 1 0 11 12 1 1

[R] Crosstabulation with a frequency variable

2015-08-13 Thread Dean1
Hi all, I've had a few years experience with R, which is why this is so frustrating, my problem seems so simple but I can't find a solution. I have a data frame in the following form: data.frame(var1=c(0,0,1,1),var2=c(0,1,0,1),freq=c(11,12,13,14)) How do I create a crosstab with frequencies?