Re: [R] How to average values from grid cells with coordinates

2018-05-23 Thread Jim Lemon
Hi lili, You can extend it like this. I checked this with two values each for pop and mood, and it looked okay. Obviously I didn't check the result with 365 values for each, but it ran okay. # these values are the centers of the black cells lat<-rep(28:38,11) lon<-rep(98:108,each=11)

Re: [R] How to average values from grid cells with coordinates

2018-05-21 Thread lily li
Hi Jim, Thanks. It works. I now have more complex problems. If at each blackcell, there are two variables such as pop and mood. For each variable, there are daily records in one year, so 365 records for pop and 365 records for mood. The averaged values for the redcells should be daily records

Re: [R] How to average values from grid cells with coordinates

2018-05-20 Thread Jim Lemon
Hi lily, It's not too hard to do it using dataframes. Getting the indexing right is usually that hardest part: # these values are the centers of the black cells lat<-rep(28:38,11) lon<-rep(98:108,each=11) pop<-sample(80:200,121) # just use the data.frame function

Re: [R] How to average values from grid cells with coordinates

2018-05-19 Thread Jim Lemon
Hi lily, You could also create "blackcells" as a dataframe (which is itself a type of list). I used a list as I thought it would be a more general solution if there were different numbers of values for different grid cells. The use of 1 for the comparison was due to the grid increments being 1. If

Re: [R] How to average values from grid cells with coordinates

2018-05-18 Thread lily li
Hi Jim, Thanks. Yes, the two assumptions are correct, and they reflect the datasets. I have an uncertainty about the code below. Why do you use abs(blackcells[[i]]$lat - redcell$lat) <1 rather than a different number than 1? Second, why to construct blackcells as a list, rather than a dataframe.

Re: [R] How to average values from grid cells with coordinates

2018-05-16 Thread Jim Lemon
Hi lily, There are one or two assumptions to be made here. First is that the latitude and longitude values of the "black" cells are equally spaced as in your illustration. Second, that all latitude and longitude values for the "red" cells fall at the corners of four "black" cells. You can get the