Hi List, I have a raster and a polygon with attribute ID and Class. I want to have the fraction of each class present in each pixel of raster. I have use the raster::extract to get the value and weights as below. ex<-extract(raster,polygon,weighted=TRUE) this gives me [[1]] value weight 13943 0.24 13958 0.02 13959 0.84 13960 0.19 13987 0.03 13988 0.31 13990 0.30 [[2]] value weight 13943 0.74 13958 0.22 13959 0.16 13960 0.80 13987 0.95 13988 0.50 13990 0.30 [[3]] value weight 13988 0.19 13990 0.40 ......... I want the output in the format as data table.
value weight ID Class 13943 0.24 1 BU 13958 0.02 1 BU 13959 0.84 1 BU 13960 0.19 1 BU 13987 0.03 1 BU 13988 0.31 1 BU 13990 0.30 1 BU 13943 0.74 2 AG 13958 0.22 2 AG 13959 0.16 2 AG 13960 0.80 2 AG 13987 0.95 2 AG 13988 0.50 2 AG 13990 0.30 2 AG 13988 0.50 3 BU 13990 0.30 3 BU To do this I have down following makeDtbl<- function(x,class,id='NA') { if(!is.null(x)) data.table(x,y,z) } inputClass<-as.character(inputShape@data$CLASS) id<-as.character(inputShape@data$ID) kc<-mapply(makeDtbl,ex,inputClass,id) I got kc as [,1] [,2] [,3] value Numeric,7 Numeric,7 Numeric,2 ............................. weight Numeric,7 Numeric,7 Numeric,2 ........................ class Character,7 Character,7 Character,2 .................... id Character,7 Character,7 Character,2 .................... Now i want to convert it in a table as above. how to do this? Thanks for your suggestion AKJ -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-list-of-matrix-raster-extract-o-p-to-data-table-with-additional-colums-polygon-Id-cla-tp4634579.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.