Steve Murray
2009-Aug-20 16:50 UTC
[R] Using 'unlist' (incorrectly?!) to collate a series of objects
Dear R Users, I am attempting to write a new netCDF file (using the ncdf) package, using 120 grids I've created and which are held in R's memory. I am reaching the point where I try to put the data into the newly created file, but receive the following error:> put.var.ncdf(evap_file, evap_dims, unlist(noquote(file_list)))Error in put.var.ncdf(evap_file, evap_dims, unlist(noquote(file_list))) : put.var.ncdf: error: you asked to write 31104000 values, but the passed data array only has 120 entries! I think I understand why this is: the 120 grids contain 31104000 values in total, however, it seems that only the names of the 120 objects are being passed to the file. Earlier on in the script, I generated the file names using the following code:> for (i in seq(nrow(index))) {file_list[[i]] <- paste(index$month[i], index$year[i], sep='') print(file_list[i]) } I was hoping therefore, that when I do put.var.ncdf and use the 'unlist' function (see original section of code), that since the data associated with the names of the grids are held in memory, both the names *and data* would be passed to the newly created file. However, it seems that only the names are being recognised. My question is therefore, is there an easy way of passing all 120 grids, using the naming convention held in file_list, to an object, which can subsequently be used in the put.var.ncdf statement? Many thanks for any help, Steve _________________________________________________________________ icons.