2

I run this code but when I perform the last line the error will be appeared, I have 8 datasets and 4 GPL for my meta analysis of microarray data.

my code is here:

ds.id<-c("GSE99039","GSE6613","GSE72267","GSE7621","GSE8397","GSE83977","GSE20141","GSE20163")
ds.plat<-c("GPL570","GPL96","GPL571","GPL97")
data.files<-paste0(ds.id,"_series_matrix.txt")
data.plat<-paste0(ds.plat,".txt")
suppressWarnings(raw <- lapply(data.files, read.delim, comment.char="!"))
raw <- lapply(raw, function(x) {rownames(x) <- x[,1]; x[,-1]})
data <- lapply(raw, function(x) {if(max(x) > 100) log2(x+1) else x})
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • 1
    Can you check which of these steps where you got that error message? – Zaw Jun 21 '21 at 05:10
  • last line: data <- lapply(raw, function(x) {if(max(x) > 100) log2(x+1) else x}) – abbas karimifard Jun 21 '21 at 05:24
  • Inspect what `raw` looks like (`str(raw)`). I'm pretty sure some columns are not numeric (i.e. gene name/id). You'll have to either exclude those in your calculations or perhaps move them to rownames. – Roman Luštrik Jun 21 '21 at 05:32
  • It's not clear what you are trying to do. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Describe in words what you are trying to do. You seem to be doing `max(x)` where `x` is an entire data.frame which doesn't work – MrFlick Jun 21 '21 at 05:32

1 Answers1

1

The error comes because you are applying max on a dataframe which has mixed datatype (numeric, characters etc). The same error can be reproduced when you apply max on iris.

max(iris)

Error in FUN(X[[i]], ...) : only defined on a data frame with all numeric variables

I think you should apply log2 and max function on one column in the dataframe. For example, if the column name is called col you can do.

result <- lapply(raw, function(x) {
  if(max(x$col) > 100) 
    x$col <- log2(x$col+1)
  x
})
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • I have 8 dataset, first dataset have 220 col and 52220 row and other dataset have same dimension. these data.frames contain only numeric data and name of row is prob-id (row.names=F) – abbas karimifard Jun 21 '21 at 05:49