[R] subsetting a matrix and filling other

antonio rodriguez antonio.raju at gmail.com
Tue Nov 7 20:00:31 CET 2006


Hi,

Having a matrix F(189,6575) I want to do this:

z1<-subset(F[,1], F[,1] >= 5 & F[,1] <= 10)
.
.
.
z189<-subset(F[,189], F[,189] >= 5 & F[,189] <= 10)

I would prefer to have an empty matrix, say 'z' in order to fill its 
columns with the output of subsetting F. But each of the subsets can 
differ in length. It's to say:

length(z1)
1189

length(z2)
1238

Don't know how to set up this with a for loop or the use of apply:

z<-189
for (i in 1:189)
{z[i]<-subset(F.zoo[,i], F.zoo[,i] >= 5 & z1 <= 10)}

Error in z[i] <- subset(F.zoo[, i], F.zoo[, i] >= 5 & z1 <= 10) :
        nothing to replace with

or

z<-matrix(0,6575,189)
for (i in 1:189)
{z[i]<-subset(F.zoo[,i], F.zoo[,i] >= 5 & z1 <= 10)}

new error


Thanks,

Antonio



More information about the R-help mailing list