here 1 option work. w loop through unique
names
of dataset, create logical index ==
, extract columns, unlist
, create data.frame
, , cbind
or use data.frame
(assumption number of duplicate elements equal each set)
data.frame(lapply(unique(names(df1)), function(x) setnames(data.frame(unlist(df1[names(df1)==x], use.names = false)), x))) # type model make #1 b c #2 d e f
data
df1 <- data.frame(type = "a", model = "b", make = "c", type = "d", model = "e", make = "f", check.names=false, stringsasfactors=false)
Comments
Post a Comment