I am trying to perform calculations on a list of data frames using hierarchical criteria. IE preferably I use criteria 1, but if not, criteria 2 is fine. If the data frame doesn't satisfy either it goes to Criteria 3, etc.
I want to return 3 lists of 36 observations (nrow in my data frame) & filtered by my criteria. However, neither category 1 or category 2 come back with 36 observations. Why is this?
Here is a reproducible example:
#dummy data
d1 <- data.frame(a=rnorm(6), b=1:6, c=rnorm(6), d = rnorm(6), e = rnorm(6))
d2 <- data.frame(a=1:6, b=rnorm(6), c =rnorm(6), d = rnorm(6), e = rep(NA,
times = 6))
d3 <- data.frame(a=1:6, b=rnorm(6), c= rnorm(1:6), d = rep(NA, times = 6), e
= rnorm(6))
d4 <- data.frame(a=1:6, b=rnorm(6), c =rnorm(6), d = rnorm(6), e = rep(NA,
times = 6))
d5 <- data.frame(a=rnorm(6), b=1:6, c=rnorm(6), d = rep(NA, times = 6), e =
rnorm(6))
d6 <- data.frame(a=rnorm(6), b=1:6, c=rnorm(6), d = rep(NA, times = 6), e =
rep(NA, times = 6))
my_test_data <- list(d1, d2, d3, d4, d5, d6)
test_data_rows <- rbind.fill(my_test_data)
#seperate into categories
Category1 <- list()
Category2 <- list()
Category3 <- list()
for (i in 1:NROW(test_data_rows)) {
if (!is.na(test_data_rows$e[i] == TRUE)) {
Category1[i] <- test_data_rows$e[i]*test_data_rows$c[i]*(test_data_rows$b[i]
/ test_data_rows$a[i])
} else if (!is.na(test_data_rows$d[i] == TRUE) & is.na(test_data_rows$e[i])
== TRUE) {
Category2[i] <- (0.432 * test_data_rows$d[i] * (test_data_rows$b[i] /
test_data_rows$a[i]))
} else if (is.na(test_data_rows$d[i] == TRUE) & is.na(test_data_rows$e[i] ==
TRUE)) {
Category3[i] <- (0.101 * 0.432*(test_data_rows$b[i] / test_data_rows$a[i]))
}
}
Thanks in advance for any help and advice you can give.
Aucun commentaire:
Enregistrer un commentaire