runningbirds runningbirds - 1 year ago 101
R Question

Check if each value in the column is a string or numeric

I would like to figure out whether or not each value in my column is a numerical value or a non-numerical value.

df = data.frame(help = c(456, 'superduper'),
correct_answer = c("numeric","string"))

I've tried is.numeric or is.character, on a row-by-row basis but this doesnt seem to work as the entire column is coded as a character.

I know this is a basic question, but any help is appreicated.

Answer Source

My first thought would be to consider if the value can be coerced to a number. E.g.:$help)))

The bonus is that this will work for variations on number formats like 3, 3.2 or even 3e5

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download