[R] Summary of data for each year
arun
smartpink111 at yahoo.com
Fri Feb 1 19:47:57 CET 2013
Hi,
You could use:
creek <- read.csv("creek.csv",sep="\t")
colnames(creek) <- c("date","flow")
creek$date <- as.Date(creek$date, "%m/%d/%Y")
creek1 <- within(creek, year <- format(date, '%Y'))
library(data.table)
creek2<- data.table(creek1)
creek2[,list(MEAN=.Internal(mean(flow)),MEDIAN=median(flow),MAX=max(flow),MIN=min(flow)),by=list(year)]
# year MEAN MEDIAN MAX MIN
#1: 1999 0.6365604 0.47695 7.256 0.3187
#2: 2000 0.2819057 0.20810 2.380 0.1370
#3: 2001 0.2950348 0.22260 2.922 0.1769
#4: 2002 0.5345666 0.21190 14.390 0.1279
#5: 2003 1.0351742 0.71730 10.150 0.3492
#6: 2004 0.9691180 0.65240 11.710 0.4178
#7: 2005 1.2338066 0.72790 17.720 0.4722
#8: 2006 0.5458652 0.42820 3.351 0.2651
#9: 2007 0.6331271 0.40410 9.629 0.2784
#10: 2008 0.8792396 0.64770 4.596 0.4131
#11: 2009 0.8465300 0.59450 6.383 0.3877
A.K.
----- Original Message -----
From: Janesh Devkota <janesh.devkota at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Friday, February 1, 2013 2:32 AM
Subject: [R] Summary of data for each year
Hello All,
I have a data with two columns. In one column it is date and in another
column it is flow data.
I was able to read the data as date and flow data. I used the following
code:
creek <- read.csv("creek.csv")
library(ggplot2)
creek[1:10,]
colnames(creek) <- c("date","flow")
creek$date <- as.Date(creek$date, "%m/%d/%Y")
The link to my data is https://www.dropbox.com/s/eqpena3nk82x67e/creek.csv
Now, I want to find the summary of each year. I want to especially know
mean, median, maximum etc.
Thanks.
Janesh
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list