Reputation: 301
I have a data frame with a column of list type where some of the values in the column looks exactly like below (including the c ):
c("A",B","A","A")
I want to convert the column into character type by unlisting it with the unique values separated with comma like below;
A,B
Tried to unlist the column like below but not able to get the desired output
df$col = unique(unlist(strsplit(as.character(df$col), ",")))
Upvotes: 0
Views: 363
Reputation: 893
You can use the paste0()
function to concatenate a vector of strings:
a <- c('A','B','A','A')
paste0(unique(a), collapse = ',')
[1] "A,B"
Upvotes: 1