[R] y2z question (AGD)

Martin Canon martin.canon at gmail.com
Sun Oct 25 13:02:49 CET 2015


Hi to all.

I've been trying to calculate weight-for-age z-scores with the y2z
command (AGD package).

However, I keep getting strange results.

My hypothesis is that missings are the problem.

My dataframe looks like this:

data <- structure(list(sex = structure(c(3L, 3L, 3L, 2L, 3L), .Label = c("",
"F", "M"), class = "factor"), weight = c(8.5, 8.2, 9, NA, 5.8),
    age = c(8, 9, 12, 9, 1)), .Names = c("sex", "weight", "age"
), class = "data.frame", row.names = c(NA, 5L))

Weight is in kg and age in months.
I will use WHO curves for children younger than 2 years of age.

z-score calculation:

library(AGD)
data$zeta <- y2z(y = data$weight, x = data$age/12, sex = data$sex,
                ref = get("who.wgt"))

I get:

Warning message:
In `split<-.default`(`*tmp*`, f, drop = drop, value = value) :
  number of items to replace is not a multiple of replacement length

data$zeta
[1]     NA     NA     NA -0.124     NA

However a for loop seems to work.

for (i in 1:5) {

  data$zeta[i] <- y2z(y = data$weight[i],
                 x = data$age[i]/12,
                 sex = data$sex[i],
                ref = get("who.wgt"))
}

data$zeta
[1] -0.124 -0.751 -0.635     NA  2.002

Is there a workaround so that I don't have to use a for loop?
na.action doesn't work either.

Thanks.


Martin



More information about the R-help mailing list