0

I want to build a binary matrix in R for each geohash that i have in a dataframe using alphabet letters and numbers. Therefore, i want that each geohash is matched with 1 if the corresponding letter or number is matched with alphabet or numbers, or 0 if not, in order to build a complete binary matrix for each geohash.

The reason why I want to build these matrices is because i want to apply an encode and decode deep learning algorithm for events prediction

Thank you

alphabetandnumbers <- c('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
                        'j', 'k','l', 'm', 'n', 'o', 'p', 'q', 'r', 
                        's', 
                        't', 'u', 'v', 'w','x', 'y', 'z', 
                         0,1,2,3,4,5,6,7,8,9)

names(df2sub)
t2 <- table(alphabetandnumbers, seq_along(df2sub$geohash))
t2[t2 > 1] <- 1
t2[1:1000]

I tried also this 'tactics' without any success

V1 <- df2sub[['geohash']]
V2 <- array(alphabetandnumbers, dim = length(alphabetandnumbers))

m <- as.matrix(V1)
id <- cbind(rowid = as.vector(t(row(m))), 
        colid = as.vector(t(m)))
id <- id[complete.cases(id), ]
id
out <-  matrix(0, nrow = nrow(m), ncol = max(m))
out[id] <- 1
  • alphabetandnumbers <- c('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0,1,2,3,4,5,6,7,8,9) names(df2sub) t2 <- table(alphabetandnumbers, seq_along(df2sub$geohash)) t2[t2 > 1] <- 1 t2[1:1000] –  Sep 30 '18 at 16:50
  • Please update your question rather than doing it in comments. You can refer here: https://stackoverflow.com/help/how-to-ask – Prasoon Karunan V Sep 30 '18 at 17:03
  • done could you please help me? are you able to do that? –  Sep 30 '18 at 20:21

0 Answers0