[R] unable to carry through object in a nested function
Chen, George
George.Chen at roswellpark.org
Thu Jan 23 04:50:16 CET 2014
Hi,
This is a resend of a previous message reproduced below but with sample data to run.
Thanks.
George Chen
Hi There,
I am having trouble carrying through an object listed in the outer function into the inner function of a nested pair.
--------sample data below ---------
library(plyr)
SUBJECT<-c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
STIM<-c("No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No")
CELL<-c("CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4")
SIGNAL<-c("ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC")
DAY<-c(7,7,7,7,7,7,7,7,7,7,1,1,1,1,1,1,1,1,1,1)
SIMSCORE<-c(2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5)
PrePropData<-data.frame(SUBJECT, STIM, CELL, SIGNAL, DAY, SIMSCORE)
________________________________
This is my code:
FindGreaterThanProportion<- function (y, SSThreshold) {
DenomCells<-length(y)
NumerCells<-subset(y,y>SSThreshold)
PropCells<-length(NumerCells)/DenomCells
return (PropCells)
}
GetPropPlot<- function (PrePropData, direction, SSThreshold, cell, stim) {
# Split up the dataframe with ddply and apply the function
print(direction)
print (SSThreshold)
if (direction==">") {
PropData<-ddply(PrePropData,.(SUBJECT, STIM, CELL, SIGNAL, DAY), summarise,
PROP=FindGreaterThanProportion(SIMSCORE, SSThreshold))
}
PlotSubset <- subset(PropData, PropData$STIM==stim & PropData$CELL == cell)
PropPlot<-ggplot(data=PlotSubset, aes(x=DAY, y=PROP)) +
geom_line() +
geom_point() +
facet_grid(SIGNAL~SUBJECT)
return(FinalPropPlot)
}
GetPropPlot(PrePropData, direction=">", SSThreshold=3, "CD4", "No")
When I run the code, I get this error:
[1] ">"
[1] 3
Error in subset.default(y, y > SSThreshold) :
object 'SSThreshold' not found
It seems as if SSThreshold is not being passed into FindGreaterThanProportion.
Any help would be appreciated to determine what I am doing incorrectly.
Thanks in advance.
George Chen
This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.
More information about the R-help
mailing list