[R-sig-Geo] In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL' in Shapefile and CSV Data

Noli Sicad nsicad at gmail.com
Sat Jan 2 11:04:50 CET 2010


Hi,

I am trying to join harvest_cut.csv (csv table) from LP linear
programming run to shapefile (*.dbf). I got some problem (below).

This is what I am trying to do
1.Read area from the shapefile as input to LP model. Data (Croptype, Age, Area)
2.Get result / output harvest_cut.csv
3.Link back my LP result to shapefile
4. Use spplot to display results

Problem in #3, I need to put a CROP_ID in my harvest_cut.csv before I
merge the harvest_cut data to Forest Stand shapefile.

Problem here:

for (i in 1:length(harvest.dat$Period)){
if ((forest.dat$CROPTYPE == harvest.dat$CROPTYPE) (forest.dat$AGECLASS
== harvest.dat$Cut_Age)) {harvest.dat$CROP_ID <- forest.dat$CROP_ID}
else { }
}

Any idea how to fix this? Any possible solution if this is not applicable

Thanks in advance

~~~~~~~~~~~~~~
# Reading and writing dbf from Shapefile
#JOIN BY ATTRIBUTES


getwd()
setwd('C:\\Down2\\R_forestmgt\\Carbon\\')

library(maptools)
library(sp)
library(foreign)

forest <- readShapePoly('C:\\Down2\\R_forestmgt\\Carbon\\ForestCarbonStand')

slot(forest,"data")

forest.dat <- slot(forest, "data")
forest.dat

harvest.dat <- read.csv('C:\\Down2\\R_forestmgt\\Carbon\\forest_cut.csv')

harvest.dat


names(harvest.dat) = c("Period", "CROP_ID", "Croptype", "Cut_Age", "Area_Cut")

# Problem here

for (i in 1:length(harvest.dat$Period)){
if ((forest.dat$CROPTYPE == harvest.dat$CROPTYPE) (forest.dat$AGECLASS
== harvest.dat$Cut_Age)) {harvest.dat$CROP_ID <- forest.dat$CROP_ID}
else { }
}

....

~~~~~~~~~~~~~
Error
...
233     15      15      OTO      31   56.720757
234     15      15      OTO      32 1360.429308
235     16      16      OTO      31 2025.898274
Error: attempt to apply non-function
In addition: Warning message:
In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
Execution halted
>Exit code: 1    Time: 3.692



More information about the R-sig-Geo mailing list