An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090502/a569bd8a/attachment-0001.pl>
value labes Stata vs factors
2 messages · Rob Bakker, Peter Dalgaard
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.dalgaard at biostat.ku.dk) FAX: (+45) 35327907