I have a raster, the pixel values inside the raster is equal to 1; outside is 0. I would like to write an r function that assign these 1 values = "cloud" in other way it will return cloud. otherwise clear.

I would like to keep the result as DF. like in the photo; (the photo is the result of different code so I cannot apply that to this situation)

How can I do this?


I have solved it in case someone needed;

recode_poly <- function(x){
  poly_recode = c()
  for (i in (1:1000)){
    if (x[i] == 1) {
      poly_label = "cloud" 
    } else {
      poly_label = "clear"
    poly_recode <- c(poly_recode, poly_label)
  return (poly_recode)

then you can convert poly_recode to a dataframe

but I am pretty open new solutions

Not the answer you're looking for? Browse other questions tagged or ask your own question.