[R] for loop not working

arun smartpink111 at yahoo.com
Tue Dec 25 07:40:08 CET 2012


HI Eliza,

You could try this:
set.seed(15)
mat1<-matrix(sample(1:2000,1776,replace=TRUE),ncol=444)
colnames(mat1)<-paste("Col",1:444,sep="")
res<-lapply(seq_len(ncol(mat1)),function(i) mat1[,seq(i,444,37)])

#If you want only this from 1:37, then
 res1<-lapply(1:37,function(i) mat1[,seq(i,444,37)])


A.K.



----- Original Message -----
From: eliza botto <eliza_botto at hotmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Tuesday, December 25, 2012 12:03 AM
Subject: [R] for loop not working


dear R family,i have a matrix of 444 columns. what i want to do is the following.
1. starting from column 1 i want to select every 37th column on the way. more precisely i want to select column 1, 38,75,112,149 and so on.
2.starting from column 2, i again want to select every 37th column. which means 2,39,76,113,150 and so on.
similarly starting from 3 till 37th column.
i have tried following loop command which is not working.can anyone plz see whats wrong in that?
>for (i in 1:37)

>{


>a<-e[,e[i]:444]


>}


> lapply(seq_len(1),
function(i) {


>a[,c(TRUE, rep(FALSE,1))]


>})
extremly sorry for bothering you once again..
eliza                           
    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list