Reputation: 945
I have a vector string which looks like this
A <- c("162&u", "139&u", "87&us", "175&u", "54&us", "25&us", "46&us","16650", "16776", "16689", "16844")
How do I convert it into a vector of numeric arrays that looks like this in R?
A <- c(162,139,87, 175, 54,25,46,16650, 16776, 16689, 16844)
Upvotes: 0
Views: 155
Reputation: 28461
A generalized approach:
as.numeric(gsub("\\D+", "", A))
#[1] 162 139 87 175 54 25 46 16650 16776 16689 16844
Upvotes: 1