for(i in 10:13) {
nam <- paste("mu04mun_", i, sep = "")
d <- paste0("sub04mun", i, "$des_flo_04")
assign(nam, qnorm(d))
}
Error in qnorm (d): Non-numeric argument to math function
for(i in 10:13) {
nam <- paste("mu04mun_", i, sep = "")
d <- paste0("sub04mun", i, "$des_flo_04")
assign(nam, qnorm(d))
}
Error in qnorm (d): Non-numeric argument to math function
You are applying the qnorm()
function to a text vector. See:
d <- "texto"
qnorm(d)
#> Error in qnorm(d): Non-numeric argument to mathematical function
Apparently your intention was to run qnorm()
in the des_flo_04
column of the data frame sub04mun
. For this, you need to call the object, not the text.
The suggestion of Rui will not work directly, because you can not put $
inside get
, but you can do it as follows:
for(i in 10:13) {
nam <- paste("mu04mun_", i, sep = "")
d <- paste0("sub04mun", i)
assign(nam, qnorm(d)[["des_flo_04"]])
}
It is important to note that this type of code is not recommended. The ideal here is you work with lists (save the data frames in a list) and operate on top of the lists: #