Skip to content
Prev 316243 / 398502 Next

Loops

Hello,

I think there is an error in the expression

100-(100*abs(fa1[i]/sum(fa1[i])-(1/3)))

Note that fa1[i]/sum(fa1[i]) is always 1. If it's fa1[i]/sum(fa1), try 
the following, using lists to hold the results.


# Make up some data
set.seed(6628)
p <- matrix(runif(300), nrow = 100)

idx <- seq(1, 100, by = 25)
fa <- lapply(idx, function(i) colSums(p[i:(i + 24), ]))
fa[[5]] <- colSums(p)

fab <- lapply(fa, function(x) 100 - 100*abs(x/sum(x) - 1/3))
fab

You can give names to the lists elements, if you want to.


names(fa) <- paste0("fa", 1:5)
names(fab) <- paste0("fa", 1:5, "b")


Hope this helps,

Rui Barradas

Em 27-01-2013 08:02, Francesca escreveu: