0

I have a 2D list that has two columns containing percentages of data I am collecting. Because the data is scraped, the whole list is of type character. I've tried gsub("%", "", mydata[[5]][2]) which turns that column into 9 rows of c('2', '11', '13'...) and then as.numeric(myurl[[5]][2]) but then I get NAs by coercion. If I try to call as.numeric(myurl[[5]][2]) first, I get "(list) object cannot be coerced to type 'double'".

Edit: Here is the result of using sub("%", "", myurl[[5]][2]) As you can see they're not ints and they are not formatting how I would like them to. The original data is just a column that looks fine but acts up when I try to use them numerically.

150005388
  • 1
  • 1
  • 2
    It would be easier to comment on the problem if we see sample data that produces some good and some bad results. – r2evans May 13 '20 at 19:46
  • Does this answer your question? [How to convert character of percentage into numeric in R](https://stackoverflow.com/questions/8329059/how-to-convert-character-of-percentage-into-numeric-in-r) – Sam Firke May 13 '20 at 19:48
  • Unfortunately it doesn't, it formats it into the image I added above. – 150005388 May 13 '20 at 20:02

1 Answers1

0

Can you provide an example of what the data looks like? Sounds like str_remove(.,"%") and separate() to break your list into multiple columns would work.

Jo_
  • 69
  • 6