I have a string in some text of the form "12,34,77", including the quotation marks.
I need to get the values of each of those numbers into a list. I tried using lapply and strsplit:
control2=lapply(strsplit(data$values,","),as.numeric)
but I get the error:
non character argument
What am I doing wrong?
1) strapply
1a) scalar Here is a one-liner using
strapplyfrom the gsubfn package:1b) vectorized A vectorized version is even simpler — just remove the
simplify=clike this:2) gsub and scan
2a) scalar and here is a one-linear using
gsubandscan:2b) vectorized A vectorized version would involve
lapply-ing over the components:3) strsplit
3a) scalar and here is a
strsplitsolution. Note that we split on both"and,:3b) vectorized A vectorized solution would, again, involve
lapply-ing over the components:3c) vectorized – simpler or slightly simpler: