Rob Bakker wrote:
Dear Sir/Madam,
I converted my Stata Rgenmetvl.dta file with read.dta succesfully in R's
Rgenmetvl.Rdata. However, factors give problem in certain calculations,
e.g.:
mean(Rgenmetvl$sex)
[1] NA
Warning message:
In mean.default(Rgenmetvl$sex) :
argument is not numeric or logical: returning NA
What can I do?
Factors can't be averaged. You can average a score based on a factor
though, as in
mean(c(1,2)[Rgenmetvl$sex])
or
mean(as.numeric(Rgenmetvl$sex))
These do the same thing, but the former allows you more control of the
scores asssigned. Notice that the values need to be in the order of
levels(Rgenmetvl$sex).
Alternatively, use read.dta(...., convert.factors=FALSE) to get a
version of data containing the original numeric values.
--
O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.