Hi community, I have a task that I need to complete but I couldnt figure it out. Maybe you can help me. So I have a data set which contains places over 50k.
dt1 <- data.table (places <- c("place1","place2","place3","place49998","place50000"), zipcodes <- 1:50000 )
I need to categorize this places city by city. Some zip codes are missing so they left as NA they are not that important focus point is places and city names. I didnt have any other datasets so I've created a dataset which includes cities and places like this
dt2<- data.table( city1 <- c("place1","place2"), city2 <- c("place3","place4"), city3 <- c("place49998","place50000") ) setnames(dt2,"V1","NY") setnames(dt2,"V2","LA") setnames(dt2,"V3","DC")
So what I want to achieve here is, for every row in dt1 it should look dt2 if there is a match in place names it should paste the city value of that place to the new column in dt1$city. I just started the learn R (only 1.5 months) but I think I need lapply or for-loop for this. Also I should mention that I'm not allowed to use dyplr.