An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110112/ce1e7c70/attachment.pl>
help in calculating ar on ranked vector
4 messages · Raymond Wong, Sebastián Daza, David Winsemius +1 more
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
On Jan 12, 2011, at 10:54 PM, Sebasti?n Daza wrote:
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
You CANNOT use names like that. (It makes no sense to supply a vector argument to "$".) If you want to change every instance of 3 within a group of columns. See if this works est8vo[, 77:83] <- sapply( est8vo[, 77:83], function(x) ifelse(x==3, 99, x) )
} 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:
est8vo[, 77:83] <- sapply(est8vo[, 77:83] , factor, labels=c("vac?o",
"s?", "no", "doble marca"))
for (i in 1:7) {
var.i <- var[i]
est8vo$var.i <- factor(est8vo$var.i,
Wrong. Wrong. Wrong. And please forget about using "$" inside loops in the left-hand side. It is not designed for that.
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 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.
David Winsemius, MD West Hartford, CT
1 day later
Works for my examples. But you have not specified what you actual call to ar() was. Uwe Ligges
On 12.01.2011 21:17, Raymond Wong wrote:
I was using ar(stats) to calculate autoregressive coefficient. It works on vector z, but it will not work on vector rz<-rank (z, ties.method="average"). What did I miss? Any info will be greatly appreciated. TIA [[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.