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
> 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
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
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
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
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?
: [R] crosstabulation and unlist function
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of eugen pircalabelu
> Sent: Monday, October 12, 2009 1:06 PM
> To: David Winsemius
> Cc: R-help
> Subject: Re: [R
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of eugen pircalabelu
> Sent: Monday, October 12, 2009 1:06 PM
> To: David Winsemius
> Cc: R-help
> Subject: Re: [R] crosstabulation and unlist function
>
f.melt, table ( dd, value ) )
Eric
- Original message -
From: "eugen pircalabelu"
To: "David Winsemius"
Cc: "R-help"
Date: Mon, 12 Oct 2009 13:05:33 -0700 (PDT)
Subject: Re: [R] crosstabulation and unlist function
Hello,
First of all, thank you David for your
erested in the NA occurence).
Hopefully, this time my question was a lot more clear.
Thank you very much !
- Original Message
From: David Winsemius
To: David Winsemius
Cc: eugen pircalabelu ; R-help
Sent: Mon, October 12, 2009 9:36:39 PM
Subject: Re: [R] crosstabulation and un
On Oct 12, 2009, at 3:25 PM, David Winsemius wrote:
On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:
Hello R-users,
My toy example:
aa<-c(1:5)
bb<-c(NA,2,NA,4,5)
cc<-c(1,2,NA,4,NA)
dd<-c("A","B","B","A","C")
df<-data.frame(aa,bb,cc,dd=as.factor(dd))
table(unlist(df[,1:3]))
Can anyone
On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:
Hello R-users,
My toy example:
aa<-c(1:5)
bb<-c(NA,2,NA,4,5)
cc<-c(1,2,NA,4,NA)
dd<-c("A","B","B","A","C")
df<-data.frame(aa,bb,cc,dd=as.factor(dd))
table(unlist(df[,1:3]))
Can anyone point me to what function let's me do a crosstabulation
Hello R-users,
My toy example:
aa<-c(1:5)
bb<-c(NA,2,NA,4,5)
cc<-c(1,2,NA,4,NA)
dd<-c("A","B","B","A","C")
df<-data.frame(aa,bb,cc,dd=as.factor(dd))
table(unlist(df[,1:3]))
Can anyone point me to what function let's me do a crosstabulation between
table(unlist(df[,1:3])) and df$dd?
I wan
On Thu, 13 Nov 2008, Sohail wrote:
I want to form a 3x3 crosstabulation for the signs of two vectors (i.e.
Negative, Zero, Positive). The problem is that I am simulating the data so
for some iterations one of the categories is absent. Thus the resulting
table shrinks to 3x2. I want it to be 3x3
Hello...
Which code are you using to perform the breakup into the three classes?
Can you be more specific on that?
Best regards,
Carlos J. Gil Bellosta
http://www.datanalytics.com
On Thu, 2008-11-13 at 09:57 +, Sohail wrote:
> I want to form a 3x3 crosstabulation for the signs of two vecto
I want to form a 3x3 crosstabulation for the signs of two vectors (i.e.
Negative, Zero, Positive). The problem is that I am simulating the data so
for some iterations one of the categories is absent. Thus the resulting
table shrinks to 3x2. I want it to be 3x3 with zero column corresponding to
the
16 matches
Mail list logo