I have this example data
d<-\"30,3\" class(d)
I have this character objects in one column in my work data frame and I need to be able to
A slight variation on the accepted answer, requires no packages. Using the example d <- c("1,2,3", "5,2")
d <- c("1,2,3", "5,2")
lengths(strsplit(d, ",")) > [1] 3 2
Or as a data.frame
data.frame
df <- data.frame(d = d) df$counts <- lengths(strsplit(df$d, ",")) df #---- d counts 1,2,3 3 5,2 2