[R] help with as.numeric
deanj2k
dl120 at le.ac.uk
Fri May 15 13:57:30 CEST 2009
hi everyone, wondering if you could help me with a novice problem. I have a
data frame called subjects with a height and weight variable and want to
calculate a bmi variable from the two. i have tried:
attach(subjects)
bmi <- (weight)/((height/100)^2)
but it comes up with the error:
Warning messages:
1: In Ops.factor(height, 100) : / not meaningful for factors
2: In Ops.factor((weight), ((height/100)^2)) :
/ not meaningful for factors
I presume that this means the vectors height and weight are not in numeric
form (confirmed by is.numeric) so i changed the code to:
bmi <- (as.numeric(weight))/((as.numeric(height)/100)^2)
but this just comes up with a result which doesnt make sense i.e. numbers
such as 40000 within bmi vector. Ive looked at
as.numeric(height)/as.numeric(weight) and these numbers just arnt the same
as height/weight which is the reason for the incorrect bmi. Cant anyone
tell me where I am going wrong? Its quiet frustrating because I cant
understand why a function claiming to convert to numeric would come up with
such a bizarre result.
--
View this message in context: http://www.nabble.com/help-with-as.numeric-tp23558326p23558326.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list