[Solved] Shifting strings in R
Data library (dplyr) df <- data.frame( x = c(“head”, “hand”, “key”), y = c(“car”, “nose”, “house”), z = c(“toe”, “mouse”, “ball”), stringsAsFactors = FALSE ) Code # Add new column. df_result <- df %>% mutate( new = case_when( x %in% c(“head”, “hand”) ~ x, z == “ball” ~ z, TRUE ~ NA_character_ ) ) # … Read more