From character vector or data frame how can I separate numbers and strings


Is there an alternative solution for this

b<-as.numeric(a[1:5])  # Not using the address of the values

How to separate numbers from a vector or dataframe w/o using above method.

You can use regular expresions (regex)

b <- as.numeric(grep("[0-9]",a,value = TRUE))
#> [1] 1 2 3 4 5

Created on 2019-01-17 by the reprex package (v0.2.1)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.