[R] Filling a grid based on existing data

Steve Murray smurray444 at hotmail.com
Thu Mar 25 12:01:15 CET 2010


Sorry, that was a poorly worded question. You're right in that the gaps are in fact NAs and I would be proposing to remove these entirely. So it's really a case of filling up a 720 x 360 grid (by row) based on the data in the 18556 rows x 19 columns data frame.

I've tried doing:

data_mat <- matrix(data, nrow=360, ncol=720, byrow=TRUE)
Warning message:
In matrix(river, nrow = 360, ncol = 720, byrow = TRUE) :
  data length [19] is not a sub-multiple or multiple of the number of rows [360]

But this results in a mess!

 head(data_mat)
     [,1]          [,2]          [,3]          [,4]          [,5]         
[1,] Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556
[2,] Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556
[3,] Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556
[4,] Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556
[5,] Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556
[6,] Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556 Numeric,18556


If it's of any use, the original data are structured as follows:

str(data)
'data.frame':   18556 obs. of  19 variables:
 $ V1 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V2 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V3 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V4 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V5 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V6 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V7 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V8 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V9 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ V10: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V11: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V12: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V13: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V14: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V15: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V16: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V17: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V18: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V19: num  0 0 0 0 0 0 0 0 0 0 ...


Don't worry about all the zeros - there are plenty of greater values later on!

Any help would be gratefully received. Thanks,

Steve


----------------------------------------
> From: dwinsemius at comcast.net
> To: smurray444 at hotmail.com
> Subject: Re: [R] Filling a grid based on existing data
> Date: Wed, 24 Mar 2010 20:50:40 -0400
>
>
> On Mar 24, 2010, at 2:34 PM, Steve Murray wrote:
>
>>
>> Dear all,
>>
>> I currently have a data frame of dimensions 18556 rows by 19
>> columns. I want to convert this into a grid of dimensions 720 rows
>> by 360 columns. The problem in this case is that not all rows in the
>> initial data frame are complete (there are gaps).
>>
>> Therefore I am perhaps looking for a way of filling a 720 x 360 grid
>> by reading in all values in each row until one is encountered which
>> does not have 19 columns. In these cases, the row in the new grid
>> should be filled (as the gaps occur every 720 values), and filling
>> should re-start on the next row of the new grid. I hope this is
>> reasonably clear!
>
> Perhaps it could become clearer. Dataframes in R do not have "gaps".
> They may have NA's but all the columns and rows have _something_.
> And ... with what were you proposing to Fill these "gaps".
>
> --
> David
>
>>
>> Many thanks for any help,
>>
>> Steve
>>
>>
>> _________________________________________________________________
>> Got a cool Hotmail story? Tell us now
>>
>> ______________________________________________
>> 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.
>
 		 	   		  
_________________________________________________________________
Do you have a story that started on Hotmail? Tell us now



More information about the R-help mailing list