Row number using grep()

#Descritive Statistics
#Data set of Chiaretti et al

library(Biobase); library(multtest); library(genefilter)
library(ALL); library(hgu95av2.db)

data(ALL) #Load the data set
ALL #print an overview of the "object"
ALL@phenoData@varMetadata #Print contents of a "slot" of an object

library(genefilter) #filtering genes
X <- exprs(ALL) #expression of data matrix

So the question was " At which row are the data for the gene '32562_at'?" I can't get grep() to work I think because 32562_at is not a value, but a label. So I'm not sure what other commands can give me the answer.

The correct answer is: row 2585

Hello @42han ,

do you mean 'rowname' when you say 'label'?
In that case you can do the grep on the rownames as below. Otherwise please explain.

In the code below I am looking for gene '4_at' (instead of '32562_at') :

n <- 5
df1 <- data.frame(
  f1 = seq(n),
  f2 = seq(n) ^ 0.5,
  f3 = paste0("cm",seq(n)),
  row.names=paste0(seq(n),"_at")
)
print(df1)
#>      f1       f2  f3
#> 1_at  1 1.000000 cm1
#> 2_at  2 1.414214 cm2
#> 3_at  3 1.732051 cm3
#> 4_at  4 2.000000 cm4
#> 5_at  5 2.236068 cm5

pattern <- "^4_at$"

df1[grep(pattern,rownames(df1)), ,drop=F]
#>      f1 f2  f3
#> 4_at  4  2 cm4
Created on 2021-11-30 by the reprex package (v2.0.0)

?which may do it.

which(mydata$gene == '32562_at')

Ya, that lets me pull the data for the gene, but I'm not sure how to get the row number it represents. Other than looking directly in the data set, I don't know how to get the row 2585.

grep(pattern,rownames(df1))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.