Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

I have the below function in R. How can I print the output of 'llod' (from the second last line) outside this function?

New member
Joined
Feb 3, 2023
Messages
7
I have the below function in R. How can I print the output of 'llod' (from the second last line) outside this function?


Code:
apply.llod <- function(vst.grp) {
  vst.grp.ercc <- vst.grp[grepl('ERCC', rownames(vst.grp)), ]
  dat <- data.frame(
    gene <- rep(rownames(vst.grp.ercc), times=ncol(vst.grp)),
    expr <- as.vector(vst.grp.ercc),
    conc <- concentration[rep(rownames(vst.grp.ercc), times=ncol(vst.grp))])
  lm <- lm(expr ~ conc, dat)
  seg <- segmented(lm, ~conc)
  lld <- seg$psi[2]
  llod <- predict(seg, data.frame(conc=lld))[[1]]
}
 
New member
Joined
Feb 3, 2023
Messages
8
Code:
apply.llod <- function(){
    lm <- lm(mpg ~ cyl,data = mtcars)
    llod <- predict(lm, mtcars)[[1]]
    llod
}

apply.llod()
> apply.llod()
[1] 20.62984
 
Top