'Transforming dataframe into some format
Solution 1:[1]
Its ideal to also share some dummy data so that its easier for us to respond.
tidyr option using separate_rows()
library(dplyr)
df %>%
tidyr::separate_rows(tenant_id,sep=" ") # assuming the separator is a space
Solution 2:[2]
Well, it would be nice if you can use the data, but you can use something like that.
library(stringr)
df = data.frame(property_type = c(1,2,3),
tenant_id = c('1 1 1 1 1', '2 2 2 2', '3 3 3'))
df = data.frame(do.call(rbind, with(
df, mapply(\(p, t) cbind(p, str_split(t, ' ')[[1]]), property_type, tenant_id)
)))
colnames(df) = c('property_type', 'tenant_id')
df
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vinay |
| Solution 2 | jassis |



