Hi lily,
If you want to use aggregate, supply the name of the function:
aggregate(flow~year, data=df, "sum")
You can also use "by" like this
by(df$flow,df$year,FUN=sum)
I assume that you don't have to worry about missing months in a year.
Jim
:
On Thu, Dec 1, 2016 at 3:06 PM, lily li wrote:
> On 1 Dec 2016, at 05:06, lily li wrote:
>
> Hi R users,
>
> I'm trying to manipulate dataset, but met some difficulties.
>
> df
> year month flow
> 2006 33.5
> 2006 43.8
> 2006 521
> 2006 632
> 2007 34.1
> 2007 44.4
Hi R users,
I'm trying to manipulate dataset, but met some difficulties.
df
year month flow
2006 33.5
2006 43.8
2006 521
2006 632
2007 34.1
2007 44.4
...
I want to calculate total flow for each year, and use the code bel
just assign it to an object
x<- DT .
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
On Sun, Nov 27, 2016 at 2:03 AM, lily li wrote:
> Thanks Jim, this method is very convenient and is what I want. Cou
Thanks Jim, this method is very convenient and is what I want. Could I know
how to save the resulted dataframe? It printed in the console directly.
On Sat, Nov 26, 2016 at 5:55 PM, jim holtman wrote:
> You did not provide any data, but I will take a stab at it using the
> "dplyr" package
>
> lib
You did not provide any data, but I will take a stab at it using the
"dplyr" package
library(dplyr)
DT %>%
group_by(month, id, note) %>%
summarise(avg = mean(total))
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you
A reproducible example was not provided, but I think what is wanted is
either ?tapply or ?ave; e.g.
within(DF, means <- ave(total, note, month, FUN = mean))
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka
Hi,
It may help that:
aggregate(DF$total, list(DF$note, DF$id, DF$month), mean)
should give you means broken down by time slice (note), id and month.
You could then subset means for GA or GB from the aggregated dataframe.
Philip
On 27/11/2016 3:11 AM, lily li wrote:
Hi R users,
I'm trying
Hi R users,
I'm trying to manipulate a dataframe and have some difficulties.
The original dataset is like this:
DF
year month total id note
2000 1 98GA 1
2001 1100 GA 1
2002 2 99GA 1
2002 2 80GB 1
...
2012 1
9 matches
Mail list logo