Hello! All, I am working on 10000x1000 matrix say 'mat' and i want to subset this matrix in a fashion that in new matrix i get columns 2,3,9,10,16,17,23,24.......so on. That is pair of columns after every interval of 7. I tried following but i got an error which is obvious.>dim(mat)[1] 10000 10>a=mat[,c(seq(c(2,3),ncol(mat),7))]Warning messages: 1: In if (n < 0L) stop("wrong sign in 'by' argument") : the condition has length > 1 and only the first element will be used 2: In if (n > .Machine$integer.max) stop("'by' argument is much too small") : the condition has length > 1 and only the first element will be used 3: In if (dd < 100 * .Machine$double.eps) return(from) : the condition has length > 1 and only the first element will be used 4: In 0L:n : numerical expression has 2 elements: only the first used Is there any other way to do it?? Please, help! regards Lee [[alternative HTML version deleted]]
David Winsemius
2010-Apr-08 12:01 UTC
[R] subsetting a matrix with specified no of columns
On Apr 8, 2010, at 7:39 AM, Lee William wrote:> Hello! All, > > I am working on 10000x1000 matrix say 'mat' and i want to subset > this matrix > in a fashion that in new matrix i get columns > 2,3,9,10,16,17,23,24.......so > on. That is pair of columns after every interval of 7. I tried > following but > i got an error which is obvious.a <- mat[ , sort( c(seq(2, 1000, by=7), 1 +seq(2, 1000, by=7)))]> >> dim(mat) > [1] 10000 10 > >> a=mat[,c(seq(c(2,3),ncol(mat),7))] > Warning messages: > 1: In if (n < 0L) stop("wrong sign in 'by' argument") : > the condition has length > 1 and only the first element will be used > 2: In if (n > .Machine$integer.max) stop("'by' argument is much too > small") > : > the condition has length > 1 and only the first element will be used > 3: In if (dd < 100 * .Machine$double.eps) return(from) : > the condition has length > 1 and only the first element will be used > 4: In 0L:n : numerical expression has 2 elements: only the first used > > Is there any other way to do it?? Please, help! > > regards > Lee > > [[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.David Winsemius, MD West Hartford, CT
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Lee William > Sent: Thursday, April 08, 2010 4:40 AM > To: r-help at r-project.org > Subject: [R] subsetting a matrix with specified no of columns > > Hello! All, > > I am working on 10000x1000 matrix say 'mat' and i want to > subset this matrix > in a fashion that in new matrix i get columns > 2,3,9,10,16,17,23,24.......so > on. That is pair of columns after every interval of 7. I > tried following but > i got an error which is obvious. > > >dim(mat) > [1] 10000 10 > > >a=mat[,c(seq(c(2,3),ncol(mat),7))]You could use a logical subscript like a <- mat[ , seq_len(ncol(mat))%%7 %in% c(2,3)] Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> Warning messages: > 1: In if (n < 0L) stop("wrong sign in 'by' argument") : > the condition has length > 1 and only the first element will be used > 2: In if (n > .Machine$integer.max) stop("'by' argument is > much too small") > : > the condition has length > 1 and only the first element will be used > 3: In if (dd < 100 * .Machine$double.eps) return(from) : > the condition has length > 1 and only the first element will be used > 4: In 0L:n : numerical expression has 2 elements: only the first used > > Is there any other way to do it?? Please, help! > > regards > Lee > > [[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. >
Seemingly Similar Threads
- head.matrix can return 1000s of columns -- limit to n or add new argument?
- reexpand a matrix after subsetting
- selective subsetting of a correlation matrix
- head.matrix can return 1000s of columns -- limit to n or add new argument?
- head.matrix can return 1000s of columns -- limit to n or add new argument?