Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205372

Keep layer name after rasterize

$
0
0

I have a data frame with x, y, values and unique IDs of 50 locations. I converted this data frame to a raster, but I lost the unique IDs of these locations. How can I preserve the name of each location within the created raster?

Pred13 = data.frame(x,y,Index)
coordinates(Pred13) = ~x+y
rst_pred_13 <- raster()
extent(rst_pred_13) <- extent(Pred13)
Pred_Yld13 = rasterize(Pred13, rst_pred_13, Pred13, fun = mean) 

This is just convert to raster, but the names (unique ID) are not there anymore.

ID      x           y           Index
D103    574070.6    4452182.5   0.716371109
D104    574969.4    4452182.5   0.744886447
D105    575868.2    4452182.5   0.748975528
D106    576767      4452182.5   0.766794456
S107    577665.8    4452182.5   0.693888885
S108    578564.6    4452182.5   0.711575956
S109    579463.4    4452182.5   0.665713451
S110    580362.2    4452182.5   0.66711642
S111    581261      4452182.5   0.744038446
F112    582159.8    4452182.5   0.698995257
F113    583058.6    4452182.5   0.645033871
F114    583957.4    4452182.5   0.661884746
F115    584856.2    4452182.5   0.661850527
F116    585755      4452182.5   0.59968895
R117    586653.8    4452182.5   0.693592996
R118    587552.6    4452182.5   0.744853835
M119    588451.4    4452182.5   0.746308897
M120    589350.2    4452182.5   0.742065499
M121    590249      4452182.5   0.715676129
M122    591147.8    4452182.5   0.662452103

Viewing all articles
Browse latest Browse all 205372

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>