Hi guys,
I hope you can help me with this (probably) simple query:
I have a data frame:
--
a=c(1,1,1,1,1,1,2,2,2,2,2,2)
b=c(1,1,1,2,3,4,1,1,2,2,3,4)
c=c(400,200,300,100,500,300,200,100,500,400,200,100)
data=data.frame(a=a,b=b,c=c)
--
And I
Hi Ben,
let me suggest some background reading - Peter Dalgaard's or Phil
Spector's book will set you up with what you need. You can also read one
of the many free, contributed sets of notes kept on CRAN.
I hope that this helps
Andrew
On Mon, Feb 4, 2013 at 8:29 PM, Benjamin Gillespie
try this:
a - c(1,1,1,1,1,1,2,2,2,2,2,2)
b - c(1,1,1,2,3,4,1,1,2,2,3,4)
c - c(400,200,300,100,500,300,200,100,500,400,200,100)
DF - data.frame(a, b, c)
with(DF, tapply(c, list(a, b), sum))
I hope it helps.
Best,
Dimitris
On 2/4/2013 10:29 AM, Benjamin Gillespie wrote:
Hi guys,
I hope you
Here are some examples of data aggregation functions in R:
http://www.slideshare.net/djandrija/data-aggregation-in-r
http://www.psychwire.co.uk/2011/04/data-aggregation-in-r-plyr-sqldf-and-data-table/
Andrija
On Mon, Feb 4, 2013 at 10:29 AM, Benjamin Gillespie gy...@leeds.ac.ukwrote:
Hi
Hello,
First, don't use data for a data frame, as it is a R function.
Here is a way to do what you are looking for:
a=c(1,1,1,1,1,1,2,2,2,2,2,2)
b=c(1,1,1,2,3,4,1,1,2,2,3,4)
c=c(400,200,300,100,500,300,200,100,500,400,200,100)
dat=data.frame(a=a,b=b,c=c)
dat.sum - aggregate(c ~ a+b, dat,
...@erasmusmc.nl]
Sent: 04 February 2013 09:35
To: Benjamin Gillespie
Cc: r-help@r-project.org
Subject: Re: [R] Script for conditional sums of vectors
try this:
a - c(1,1,1,1,1,1,2,2,2,2,2,2)
b - c(1,1,1,2,3,4,1,1,2,2,3,4)
c - c(400,200,300,100,500,300,200,100,500,400,200,100)
DF - data.frame(a, b, c
Hello,
In what follows, I've renamed the data.frame 'dat', 'data' already is an
R function.
xtabs(c ~ a + b, data = dat)
Hope this helps,
Rui Barradas
Em 04-02-2013 09:29, Benjamin Gillespie escreveu:
Hi guys,
I hope you can help me with this (probably) simple query:
I have a data
] Script for conditional sums of vectors
Hi guys,
I hope you can help me with this (probably) simple query:
I have a data frame:
--
a=c(1,1,1,1,1,1,2,2,2,2,2,2)
b=c(1,1,1,2,3,4,1,1,2,2,3,4)
c=c(400,200,300,100,500,300,200,100,500,400,200,100)
data=data.frame(a=a,b=b,c=c
8 matches
Mail list logo