Dear R Users, I am using the reshape package to reformat gridded data into column format using the code shown below. However, when I display the resulting object, a single column is fomed (instead of three) and all the latitude values (which should be in either column one or two) are collected at the bottom. Also, the NA values aren't removed, despite this being requested in the code.
Code: # NetCDF file has been read in and is being processed... arunoff_1986_temp <- get.var.ncdf(netcdf_1036_temp, "arunoff") # Assign row and column names columnnames <- sprintf("%.2f", seq(from = -89.75, to = 89.75, length = 360)) rnames <- sprintf("%.2f", seq(from = -179.75, to = 179.75, length = 720)) colnames(arunoff_1986_temp) <- columnnames rownames(arunoff_1986_temp) <- rnames # Melt into columnar format arunoff_1986$Longitude <- rownames(arunoff_1986) # Note: If I do: arunoff_1986$Latitude <- rownames(arunoff_1986) (i.e. change it to 'Latitude', I get the following: Warning message: In arunoff_1986$Latitude <- rownames(arunoff_1986) : Coercing LHS to a list ), thus proceed using 'Longitude' where no warning is apparent. arunoff_long_1986 <- melt(arunoff_1986, id.var="Longitude", na.rm=TRUE) > dim(arunoff_long_1986) [1] 259560 2 >head(arunoff_long_1986, n=10) # This displays what looks like one single >column, but is in fact two: column entitled "L1" is empty until the end of the >file, as shown by the 'tail' command below. value L1 1 2 3 4 5 6 7 8 9 10 > tail(arunoff_long_1986, n=10) value L1 Latitude.351 85.25 Latitude Latitude.352 85.75 Latitude Latitude.353 86.25 Latitude Latitude.354 86.75 Latitude Latitude.355 87.25 Latitude Latitude.356 87.75 Latitude Latitude.357 88.25 Latitude Latitude.358 88.75 Latitude Latitude.359 89.25 Latitude Latitude.360 89.75 Latitude I'd be very grateful indeed if anyone is able to offer assistance by way of pointing out what I've done wrong. I've spent a long time working on this and trying various options, but am srill none the wiser! I'm aiming for three columns: Latitude, Longitude, 'value'. Many thanks for any help offered, Steve ______________________________________________ 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.