So basically I have a list called "parameters" with values (x1, x2, ... , xj). I want to, through a for loop, subset this list, but each time leave out one element. So for example I want the first subset (through the first iteration of the for loop) to be (x2, x3, ..., xj), and the next to be (x1, x3, ..., xj) and so on, until the last subset which would be (x1, x2, ... , xj-1). How do I do this?
this could be useful
> Vector <- paste("x", 1:6, sep="")
> lapply(1:length(Vector), function(i) Vector[-i])
I'm assuming by "list" you mean vector
. If so:
parameters <- rnorm(100)
y <- matrix(nrow=length(parameters)-1,ncol=length(parameters))
for(i in 1:length(parameters))
y[,i] <- parameters[-i]
If by "list", you actually mean a list
, the code is basically the same, but just do parameters <- unlist(parameters)
first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With