Problems substituting slot name with string variable
2
0
Entering edit mode
Edwin Groot ▴ 230
@edwin-groot-3606
Last seen 9.7 years ago
Hello all, I am trying to repeat a hypergeometric test 40 times by putting it in a loop, but I am missing something as it does not work. How do I substitute a slot name with a string variable? Here is the code so far: > probTable <- data.frame(row.names=rownames(repData)) > for (dataset in rownames(sizeData)) { + probVector <- phyper(repData$`dataset`-1, + repData$size, totalGenes-repData$size, + sizeData[`dataset`,], lower.tail = FALSE); probTable$`dataset` <- probVector } Error in `$<-.data.frame`(`*tmp*`, "dataset", value = numeric(0)) : replacement has 0 rows, data has 492 The point here is that backticking is not working for me: repData$`dataset` returns NULL. I tried variations on single quotes, substitute(), eval() and evalq(), but none work! FYI the sizeData object is a data frame of 40 rows. The repData object is a data frame of 492 rows and 41 columns. The names of 40 of the columns are identical to the names of the 40 rows in sizeData. TIA for helping me out of a mental block, Edwin p.s. R 2.11.1 i486 linux-gnu; Bioc err... 2.6 -- Dr. Edwin Groot, postdoctoral associate AG Laux Institut fuer Biologie III Schaenzlestr. 1 79104 Freiburg, Deutschland +49 761-2032945
• 660 views
ADD COMMENT
0
Entering edit mode
@sean-davis-490
Last seen 4 months ago
United States
On Tue, Jul 6, 2010 at 11:02 AM, Edwin Groot < edwin.groot@biologie.uni-freiburg.de> wrote: > Hello all, > I am trying to repeat a hypergeometric test 40 times by putting it in a > loop, but I am missing something as it does not work. > How do I substitute a slot name with a string variable? > > Here is the code so far: > > probTable <- data.frame(row.names=rownames(repData)) > > for (dataset in rownames(sizeData)) { > + probVector <- phyper(repData$`dataset`-1, > Hi, Edwin. repData[,dataset] > + repData$size, totalGenes-repData$size, > + sizeData[`dataset`,], lower.tail = FALSE); > sizeData[dataset,] > probTable$`dataset` <- probVector } > > probTable[,dataset] > Error in `$<-.data.frame`(`*tmp*`, "dataset", value = numeric(0)) : > replacement has 0 rows, data has 492 > > The point here is that backticking is not working for me: > repData$`dataset` returns NULL. > I tried variations on single quotes, substitute(), eval() and evalq(), > but none work! > You might benefit from a quick primer on R subsetting. The Intro to R manual is one place to start. Sean > > FYI the sizeData object is a data frame of 40 rows. The repData object > is a data frame of 492 rows and 41 columns. The names of 40 of the > columns are identical to the names of the 40 rows in sizeData. > > TIA for helping me out of a mental block, > Edwin > p.s. R 2.11.1 i486 linux-gnu; Bioc err... 2.6 > -- > Dr. Edwin Groot, postdoctoral associate > AG Laux > Institut fuer Biologie III > Schaenzlestr. 1 > 79104 Freiburg, Deutschland > +49 761-2032945 > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
On Tue, 6 Jul 2010 11:10:36 -0400 Sean Davis <sdavis2 at="" mail.nih.gov=""> wrote: > On Tue, Jul 6, 2010 at 11:02 AM, Edwin Groot < > edwin.groot at biologie.uni-freiburg.de> wrote: > > > Hello all, > > I am trying to repeat a hypergeometric test 40 times by putting it > in a > > loop, but I am missing something as it does not work. > > How do I substitute a slot name with a string variable? > > > > Here is the code so far: > > > probTable <- data.frame(row.names=rownames(repData)) > > > for (dataset in rownames(sizeData)) { > > + probVector <- phyper(repData$`dataset`-1, > > > > Hi, Edwin. > > repData[,dataset] > > > > + repData$size, totalGenes-repData$size, > > + sizeData[`dataset`,], lower.tail = FALSE); > > > > sizeData[dataset,] > > > probTable$`dataset` <- probVector } > > > > > probTable[,dataset] > > > > Error in `$<-.data.frame`(`*tmp*`, "dataset", value = numeric(0)) : > > replacement has 0 rows, data has 492 > > > > The point here is that backticking is not working for me: > > repData$`dataset` returns NULL. > > I tried variations on single quotes, substitute(), eval() and > evalq(), > > but none work! > > > > You might benefit from a quick primer on R subsetting. The Intro to > R > manual is one place to start. > > Sean > Thanks Sean, it worked like a charm! Of course I know [,]. It just did not click in at the time. I think I got mixed up with BASH scripting and made things overly complicated. I'll give this PDF R manual a closer read... Onward to functions! Edwin -- > > > > > > FYI the sizeData object is a data frame of 40 rows. The repData > object > > is a data frame of 492 rows and 41 columns. The names of 40 of the > > columns are identical to the names of the 40 rows in sizeData. > > > > TIA for helping me out of a mental block, > > Edwin > > p.s. R 2.11.1 i486 linux-gnu; Bioc err... 2.6 > > -- > > Dr. Edwin Groot, postdoctoral associate > > AG Laux > > Institut fuer Biologie III > > Schaenzlestr. 1 > > 79104 Freiburg, Deutschland > > +49 761-2032945 > > > > _______________________________________________ > > Bioconductor mailing list > > Bioconductor at stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/bioconductor > > Search the archives: > > http://news.gmane.org/gmane.science.biology.informatics.conductor > > Dr. Edwin Groot, postdoctoral associate AG Laux Institut fuer Biologie III Schaenzlestr. 1 79104 Freiburg, Deutschland +49 761-2032945
ADD REPLY
0
Entering edit mode
@james-w-macdonald-5106
Last seen 21 hours ago
United States
Hi Edwin, On 7/6/2010 11:02 AM, Edwin Groot wrote: > Hello all, > I am trying to repeat a hypergeometric test 40 times by putting it in a > loop, but I am missing something as it does not work. > How do I substitute a slot name with a string variable? > > Here is the code so far: >> probTable<- data.frame(row.names=rownames(repData)) >> for (dataset in rownames(sizeData)) { > + probVector<- phyper(repData$`dataset`-1, > + repData$size, totalGenes-repData$size, > + sizeData[`dataset`,], lower.tail = FALSE); > probTable$`dataset`<- probVector } > > Error in `$<-.data.frame`(`*tmp*`, "dataset", value = numeric(0)) : > replacement has 0 rows, data has 492 > > The point here is that backticking is not working for me: > repData$`dataset` returns NULL. > I tried variations on single quotes, substitute(), eval() and evalq(), > but none work! > > FYI the sizeData object is a data frame of 40 rows. The repData object > is a data frame of 492 rows and 41 columns. The names of 40 of the > columns are identical to the names of the 40 rows in sizeData. This is more suited to R-help, as there is no BioC component that I can discern. However, if you are simply trying to get the preceding column, why don't you just convert to numeric rather than trying to do parsing magic? for(i in rownames(sizeData)){ ind <- which(names(repData) == i) - 1 probVector <- phyper(repData[,ind], repData$size, totalGenes-repData$size, sizeData[i,], lower.tail=FALSE) probTable[,i] <- probVector } Best, Jim Best, Jim > > TIA for helping me out of a mental block, > Edwin > p.s. R 2.11.1 i486 linux-gnu; Bioc err... 2.6 -- James W. MacDonald, M.S. Biostatistician Douglas Lab University of Michigan Department of Human Genetics 5912 Buhl 1241 E. Catherine St. Ann Arbor MI 48109-5618 734-615-7826 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues
ADD COMMENT

Login before adding your answer.

Traffic: 549 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