[R] dummy coding problem

Bert Gunter gunter.berton at gene.com
Wed Mar 26 20:04:04 CET 2014


No you don't. You have a problem with not learning how R works. Dummy
coding is not needed in R. R uses factors instead. Read "An
Introduction to R" (ships with R) or a web tutorial of your choice to
learn how to work with R.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch




On Wed, Mar 26, 2014 at 11:34 AM, Si Qi L. <liusiqi.nine at gmail.com> wrote:
> Hi, I have got a problem with dummy coding and I really couldn't figure it
> out. Would you please help me out? this is my codes:
>
> idx<-sort(unique(Employment.time$V1));
> dummy <- matrix(NA, nrow=nrow(Employment.time), ncol= length(idx))
>
> for (i in 1:nrow(Employment.time)) {
>
> for (j in 1:length(idx)) {
>
> if (Employment.time$V1[i,j] == "Over 4 years") {
> dummy[i,j] <- 0
> }
> else {
> dummy[i,j] <- 1
> }
> }
> }
>
> but the R shows that
>
> Error in `[.default`(Employment.time$V1, i, j) :
> incorrect number of dimensions
>
> Do you know where is wrong? many thanks!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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