Hi everyone,

I am new in R and programming. I have tried to remove the values out of range in some variables using a loop:

1)

var  <- names(est8vo[, 77:83])   # I got the variable names

> var
[1] "p16.1" "p16.2" "p16.3" "p16.4" "p16.5" "p16.6" "p16.7"

for (i in 1:7)  {
var.i  <- var[i]
est8vo$var.i[ est8vo$var.i==3] <- 99
  }

I got this error:

Error in `$<-.data.frame`(`*tmp*`, "var.i", value = numeric(0)) :
  replacement has 0 rows, data has 215700


2) The second step would be to define the factors, but I got the same error:

for (i in 1:7)  {
var.i  <- var[i]
est8vo$var.i    <- factor(est8vo$var.i,
  levels=c(0, 1, 2, 99),
  labels=c("vacío", "sí", "no", "doble marca")
  )
  }


I don't know how to do it.
Thank you in advance!
Sebastian

______________________________________________
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.

Reply via email to