[R] Loop through a simulation
arun
smartpink111 at yahoo.com
Thu May 16 09:16:23 CEST 2013
HI,
Try this:
dat1<- read.csv("data2.csv",header=FALSE,sep="\t")
dim(dat1)
#[1] 345156 5
res<- aggregate(V5~V2+V3+V4,data=dat1,FUN=mean)
dim(res)
#[1] 16436 4
head(res)
# V2 V3 V4 V5
#1 1961 1 1 0.51761905
#2 1962 1 1 0.04666667
#3 1963 1 1 1.14761905
#4 1964 1 1 0.05190476
#5 1965 1 1 0.51428571
#6 1966 1 1 0.50952381
tail(res)
# V2 V3 V4 V5
#16431 2000 12 31 0.6428571
#16432 2001 12 31 0.1600000
#16433 2002 12 31 0.3314286
#16434 2003 12 31 0.2271429
#16435 2004 12 31 3.7423810
#16436 2005 12 31 1.1371429
A.K.
----- Original Message -----
From: "Zilefac, Elvis" <aez849 at mail.usask.ca>
To: arun <smartpink111 at yahoo.com>
Cc:
Sent: Thursday, May 16, 2013 2:25 AM
Subject: RE: Loop through a simulation
Dear AK,
Here is data from 21 simulations or so.
Thanks so much.
________________________________________
From: arun [smartpink111 at yahoo.com]
Sent: Thursday, May 16, 2013 12:04 AM
To: Zilefac, Elvis
Subject: Re: Loop through a simulation
Dear Zilefac,
I am not able to download your dataset. It says "An error occured while downloading". Could you send a smaller dataset? For example the data between 1961-1965 or so.
________________________________
From: "Zilefac, Elvis" <aez849 at mail.usask.ca>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com>
Sent: Thursday, May 16, 2013 1:05 AM
Subject: Loop through a simulation
Dear AK,
Please help again. I have this data file to loop through. The columns are as follows:
[simulation, year, month, day, rainfall_values]
I have daily data from 1961 to 2005 . I have made 63 stochastic simulations each from 1961 to 2005.
Now, I would like to obtain the values for each rainfall_value, which is the mean from 63 such values.
For example, rainfall_value of row one should be the mean(simulation 1 row 1, simulation 2 row 1,...simulation 63 row 1) etc. In the end, you will have daily data from 1961 to 200, same length as simulation 1 ,for example.
Thanks so much for this great help.
Atem.
More information about the R-help
mailing list