[R] Levels and labels in factor
Blaser Nello
nblaser at ispm.unibe.ch
Wed Apr 10 10:58:57 CEST 2013
Perhaps write.dta(..., convert.factors="string") might help.
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of chong shiauyun
Sent: Mittwoch, 10. April 2013 10:01
To: r-help at r-project.org
Subject: [R] Levels and labels in factor
Hi R users, I have a imputed dataset of undefinedundefined cycles which
I generated using StAta version undefinedundefined. Then I imported my
data from Stata into R and I used a loop to run Mclust package in R. My
observation starts with ID=2 (ID=1 has been excluded from the sample)
and ends with 27950. Here is my code:
library(mclust)
library(foreign)
dat<-read.dta(file="tempeundefined.dta")
impdat<-subset(dat,mim!=undefined)
datn<-impdat
apply(datn,undefined,range)
fix(datn)
mdlnc<-matrix(,undefinedundefined,undefined)
undefinedgetting the final output
n<-dim(datn)[undefined]
datf<-matrix(undefined,n,undefined)
for(i in undefined:undefinedundefined){
set.seed(undefinedundefinedundefinedundefinedundefinedundefined)
datnss <- subset(datn, mim==i)
datnssMclust<-Mclust(datnss[,undefined:undefinedundefined],model="VEV",G
=undefined)
zv<-datnssMclust$z
clas<-datnssMclust$classification
zval<-cbind(zv,clas))
colnames(zval)<-c("Pundefined","Pundefined","Pundefined","class")
impd<-datnss[,c("cid_undefinedundefinedundefineda","qlet","mim")]
fd<-as.matrix(cbind(impd,zval))
datf[((undefinedundefinedundefinedundefinedundefined*(i-undefined)+undef
ined):(i*undefinedundefinedundefinedundefinedundefined)),]<-fd
}
cid_731a is my observation ID and mim is the number of imputed dataset.
When I write the output in dta format (Stata data format), the IDs were
reorganised. ID is now started with 1,2,3,4,...13797 which is not right.
Label values have been attached to the existing data. The variables were
now in long format. I guess that is because the factor in R is always
begins with 1,2,3,4,... Is there anyway I can fix this? Please help
SY
______________________________________________
R-help at 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.
More information about the R-help
mailing list