[R] - combining lists

2010-08-12 Thread pelt

Hi all,

I have used this library to create a (360 day)calendar for my rainfall 
data (which is divided over 9 gridcells):


## CODE##
library(udunits)
utInit()
calendar - att.get.nc(nc,'time','calendar')
T - var.get.nc(nc,time)
times.list - utCalendar(T,days since 
1961-01-01,style='array',calendar=calendar)

## END CODE##

To separate months and years I use:

## CODE##
times.ind - lapply(as.list(1:12), function(x,months) which(months == x),
  months = times.list$month)
times.ind2 - lapply(as.list(1961:1990), function(x,years) which(years 
== x),

  years = times.list$year)
## END CODE##

Now I have two lists, the first contains months, for example, for 
times.ind[1] I get a list of day numbers which are from January. (so 
1:30, 361:390 etc)

The other list does the same for years times.ind2[1] gives the days 1:360

It is now possible for me to create for example monthly averages for 
each grid cell

##CODE##
pr.monthmean - sapply(times.ind, function(x,arr) rowMeans(arr[,,x],dims=2),
  arr = pr)
## END CODE##

the same can be done for yearly averages.

However, I would like to create a matrix with monthly averages for each 
year separately. I think I need to couple times.ind and times.ind2 in 
some way, but I do not know how to do this. Is there anyone who can help 
me with this?


Thank you in advance,

Kind regards,

Saskia

__
R-help@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.


[R] combining lists of pairs

2008-07-17 Thread olvrmrs
Hi everybody,

This has been causing me some trouble:

I want to combine several lists of pairs into a single?vector but keep the 
pairs together. The lists are of the form:
(1)?x1 x2 x3... N? 
(2) y1 y2 y3..? N

I would like to keep it this way, simply appending one list to another, e.g.
(1) x1i x2i... x1j x2j... N
(2) etc.

A?method like c(...) does not achieve this. It creates a single list, 
disregarding the pairs.

Is there a more efficient way of doing it?

Thanks!
Oliver Marshall

[[alternative HTML version deleted]]

__
R-help@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.