genefilter problem
1
0
Entering edit mode
@wxumsiumnedu-1819
Last seen 10.2 years ago
Hello, I created a filter function to filter the microarray data set by row variance, but got follow error: > dim(data1) [1] 7129 38 > data1[1,2:4] data[, 4] data[, 6] data[, 8] 1 -139 -76 -135 > myfilter<-function(j){ + function(x){ + rowVars(x)<j +="" }="" +="" }=""> > ff<-filterfun(myfilter(20)) > filt<-genefilter(data1,ff) Error in rowSums(!is.na(x)) : 'x' must be an array of at least two dimensions I know the error occurred in: > rowSums function (x, na.rm = FALSE, dims = 1) { if (is.data.frame(x)) x <- as.matrix(x) if (!is.array(x) || length(dn <- dim(x)) < 2) stop("'x' must be an array of at least two dimensions") if (dims < 1 || dims > length(dn) - 1) stop("invalid 'dims'") p <- prod(dn[-(1:dims)]) dn <- dn[1:dims] z <- if (is.complex(x)) .Internal(rowSums(Re(x), prod(dn), p, na.rm)) + (0+1i) * .Internal(rowSums(Im(x), prod(dn), p, na.rm)) else .Internal(rowSums(x, prod(dn), p, na.rm)) if (length(dn) > 1) { dim(z) <- dn dimnames(z) <- dimnames(x)[1:dims] } else names(z) <- dimnames(x)[[1]] z } <environment: namespace:base=""> I wrote other filters and they work fine, but the rowVars or rowSums function does not work for me. Can someone help? Thanks in advance ! Wayne --
Microarray Microarray • 1.8k views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 4 months ago
United States
Hi Wayne -- Wayne Xu <wxu at="" msi.umn.edu=""> writes: > Hello, > > I created a filter function to filter the microarray data set by row > variance, but got follow error: > > > dim(data1) > [1] 7129 38 > > data1[1,2:4] > data[, 4] data[, 6] data[, 8] > 1 -139 -76 -135 > > > > myfilter<-function(j){ > + function(x){ > + rowVars(x)<j> + } > + } > > > > ff<-filterfun(myfilter(20)) > > filt<-genefilter(data1,ff) > Error in rowSums(!is.na(x)) : > 'x' must be an array of at least two dimensions genefilter feeds the filter function each row as a simple vector, so try myfilter = function(j) function(x) var(x) < j Here's what I did... > m = matrix(1:20, 5) > myfilter = function(j) function(x) rowVars(x) < j > options(error=recover) > genefilter(m, filterfun(myfilter(2))) genefilter(m, filterfun(myfilter(2))) Error in rowSums(!is.na(x)) : 'x' must be an array of at least two dimensions Enter a frame number, or 0 to exit 1: genefilter(m, filterfun(myfilter(2))) 2: apply(expr, 1, flist) 3: FUN(newX[, i], ...) 4: fun(x) 5: rowVars(x) 6: rowSums(!is.na(x)) Selection: 4 Called from: eval(expr, envir, enclos) Browse[1]> x [1] 1 6 11 16 # Aha, a vector not a matrix with 1 row! Browse[1]> Q > options(error=NULL) Hope that helps, Martin > I know the error occurred in: > > rowSums > function (x, na.rm = FALSE, dims = 1) > { > if (is.data.frame(x)) > x <- as.matrix(x) > if (!is.array(x) || length(dn <- dim(x)) < 2) > stop("'x' must be an array of at least two dimensions") > if (dims < 1 || dims > length(dn) - 1) > stop("invalid 'dims'") > p <- prod(dn[-(1:dims)]) > dn <- dn[1:dims] > z <- if (is.complex(x)) > .Internal(rowSums(Re(x), prod(dn), p, na.rm)) + (0+1i) * > .Internal(rowSums(Im(x), prod(dn), p, na.rm)) > else .Internal(rowSums(x, prod(dn), p, na.rm)) > if (length(dn) > 1) { > dim(z) <- dn > dimnames(z) <- dimnames(x)[1:dims] > } > else names(z) <- dimnames(x)[[1]] > z > } > <environment: namespace:base=""> > > I wrote other filters and they work fine, but the rowVars or rowSums > function does not work for me. > > Can someone help? Thanks in advance ! > > Wayne -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (206) 667-2793
ADD COMMENT
0
Entering edit mode
Thanks Martin, It is very helpful, Wayne -- Martin Morgan wrote: > Hi Wayne -- > > Wayne Xu <wxu at="" msi.umn.edu=""> writes: > > >> Hello, >> >> I created a filter function to filter the microarray data set by row >> variance, but got follow error: >> >> > dim(data1) >> [1] 7129 38 >> > data1[1,2:4] >> data[, 4] data[, 6] data[, 8] >> 1 -139 -76 -135 >> >> >> > myfilter<-function(j){ >> + function(x){ >> + rowVars(x)<j>> + } >> + } >> > >> > ff<-filterfun(myfilter(20)) >> > filt<-genefilter(data1,ff) >> Error in rowSums(!is.na(x)) : >> 'x' must be an array of at least two dimensions >> > > genefilter feeds the filter function each row as a simple vector, so > try > > myfilter = function(j) function(x) var(x) < j > > Here's what I did... > > >> m = matrix(1:20, 5) >> myfilter = function(j) function(x) rowVars(x) < j >> options(error=recover) >> genefilter(m, filterfun(myfilter(2))) >> > genefilter(m, filterfun(myfilter(2))) > Error in rowSums(!is.na(x)) : > 'x' must be an array of at least two dimensions > > Enter a frame number, or 0 to exit > > 1: genefilter(m, filterfun(myfilter(2))) > 2: apply(expr, 1, flist) > 3: FUN(newX[, i], ...) > 4: fun(x) > 5: rowVars(x) > 6: rowSums(!is.na(x)) > > Selection: 4 > Called from: eval(expr, envir, enclos) > Browse[1]> x > [1] 1 6 11 16 # Aha, a vector not a matrix with 1 row! > Browse[1]> Q > >> options(error=NULL) >> > > Hope that helps, > > Martin > > >> I know the error occurred in: >> > rowSums >> function (x, na.rm = FALSE, dims = 1) >> { >> if (is.data.frame(x)) >> x <- as.matrix(x) >> if (!is.array(x) || length(dn <- dim(x)) < 2) >> stop("'x' must be an array of at least two dimensions") >> if (dims < 1 || dims > length(dn) - 1) >> stop("invalid 'dims'") >> p <- prod(dn[-(1:dims)]) >> dn <- dn[1:dims] >> z <- if (is.complex(x)) >> .Internal(rowSums(Re(x), prod(dn), p, na.rm)) + (0+1i) * >> .Internal(rowSums(Im(x), prod(dn), p, na.rm)) >> else .Internal(rowSums(x, prod(dn), p, na.rm)) >> if (length(dn) > 1) { >> dim(z) <- dn >> dimnames(z) <- dimnames(x)[1:dims] >> } >> else names(z) <- dimnames(x)[[1]] >> z >> } >> <environment: namespace:base=""> >> >> I wrote other filters and they work fine, but the rowVars or rowSums >> function does not work for me. >> >> Can someone help? Thanks in advance ! >> >> Wayne >> > >
ADD REPLY

Login before adding your answer.

Traffic: 865 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6