Hello,
Try the following.
m <- unlist(months)
v <- unlist(values)
aggregate(v ~ m, FUN=sum)
tapply(v, m, sum)
Hope this helps,
Rui Barradas
Em 26-07-2012 18:49, jcrosbie escreveu:
I have two data frames. One with a matrix of months and the other with a
matrix of values. The two dataframes c
The values need not be a data frame as the number of unique months
could be different among the columns, right?. So you're going to have
to rethink your data structure. Probably as a list.
Once you get that straight,?tapply and friends should make it trivial,
if I understand you correctly.
-- Ber
I have two data frames. One with a matrix of months and the other with a
matrix of values. The two dataframes correspond to each other. I would like
to sum up all the values in by month.
What would be an efficient way to do this?
a=C(2,3,5,2,3,5)
b=c(2,6,3,2,6,3)
c=c(2,6,7,2,6,5)
months <- dat
I am still struggling (I'm an R novice). Basically I just want to sum the
values per group if the year condition is met. I have the feeling that using
a loop would work, but I am not really familiar with loops. Something like
this?
for(DF$C in 1:length(DF$C))
{
DF<-which(DF$year
Thanks for the quick response, but it doesn't do the trick. There are two
problems:
1. The ith value of the newly created variable DF$D also includes the ith
value of DF$C (this problem is easily solved by DF$D = DF$D-DF$C.)
2. If group i in DF$group appears more than once in year t, the value of
mathijsdevaan wrote:
>
> I have a DF like this:
>
> DF = data.frame(read.table(textConnection("A B C
> 1 b1 1999 0.25
> 2 c1 1999 0.25
> ..
> For each factor in A I want to sum the values of C for all years(Bn) prior
> to the current year(Bi):
>
> 1 b1 1999 0.25 0
> 2 c1 1999 0
Hi,
I have a DF like this:
DF = data.frame(read.table(textConnection("A B C
1 b1 1999 0.25
2 c1 1999 0.25
3 d1 1999 0.25
4 a2 1999 0.25
5 c2 1999 0.25
6 d2 1999 0.25
7 a3 1999 0.25
8 b3 1999 0.25
9 d3 1999 0.25
10 a4 1999 0.25
11 b4 1999 0.25
12 c4 1999 0.25
13 b1
7 matches
Mail list logo