-1

I have hundreds of P values which correspond to row names in my data frame. I put those values into a new row of the original table:

df1$Pvalues<-lapply(1:nrow(data1), function(i) { 
    wilcox.test(as.numeric(data1[i, ]), as.numeric(data2[i, ]))$p.value
}))

I found the top 20 most significant P values and now need to find out which column name they correspond to. I have tried:

which(rownames(df1) %in% c("1.136925e-12"))

But the answer given is integer(0)

Another way would be to print the top 20 most significant P values along with column names straight away but all I have is the actual P values. In this command wilcoxon is the name of the dataframe where I have subset the P values:

head(sort(wilcoxon),20)

I'm a beginner, any help would be appreciated!

magsd
  • 35
  • 5
  • 3
    Can you make your example [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? Generally, it might be easier for you to separate input from output. – Heroka Nov 02 '15 at 15:29
  • If you want to find which column they belong to, why you are comparing with `row.names`? – akrun Nov 02 '15 at 15:32
  • @akrun I Sorry, I did mean row names! – magsd Nov 02 '15 at 17:19

1 Answers1

0

So, first you need to find the 20 smallest values. E.g. sort the vector of values, then index first 20 elements. When you know which values you are looking for you can index row.names with logical vector.

x <- sort(df1$Pvalues)[1:20]

row.names(df1)[df1$Pvalues %in% x]
zielinskipp
  • 120
  • 5