[R] consolidate three function into one

Ding, Yuan Chun ycding at coh.org
Sun Jan 14 18:17:42 CET 2018


HI R users,

I construct dendrogram tree and cut the tree into different clusters, then generate survival curves by the following three functions. All variables are included in an inputfile. 

Can you help me to consolidate the following three function into one functions?  I thought about using if  else function, but not sure how to do it.

Thank you,

Ding

# function to generate RFS
RFS2cluster <- function( inputfile ) {
  cluster2<- survfit(Surv(RFS_days, OV_Had_a_Recurrence_CODE) ~ clusters,
                               data = inputfile)
  
  ggsurvplot(cluster2, data = inputfile, risk.table = F,
             palette = c("red", "black"),
             ylim=c(0,1),
             ggtheme = theme_bw(),
             xlab="Relapse Free Suvival (Days)",
             main = "Survival curve",
             pval = TRUE,
             font.x =  16,
             font.y = 16,
             font.tickslab = 14,
             font.legend =c(14,"plain","black"),
             legend = "bottom", 
             legend.title = "Tree Cluster",
             legend.labs = c("Cluster1", "Cluster2"), lty=1, lwd=3)
}

RFS3cluster <- function( inputfile ) {
  cluster3<- survfit(Surv(RFS_days, OV_Had_a_Recurrence_CODE) ~ clusters,
                     data = inputfile)
  
  ggsurvplot(cluster3, data = inputfile, risk.table = F,
             palette = c("red", "black", "green"),
             ylim=c(0,1),
             ggtheme = theme_bw(),
             xlab="Relapse Free Suvival (Days)",
             main = "Survival curve",
             pval = TRUE,
             font.x =  16,
             font.y = 16,
             font.tickslab = 14,
             font.legend =c(14,"plain","black"),
             legend = "bottom", 
             legend.title = "Tree Cluster",
             legend.labs = c("Cluster1", "Cluster2", "Cluster3"), lty=1, lwd=3)
}

RFS4cluster <- function( inputfile ) {
  cluster4<- survfit(Surv(RFS_days, OV_Had_a_Recurrence_CODE) ~ clusters,
                     data = inputfile)
  
  ggsurvplot(cluster4, data = inputfile, risk.table = F,
             palette = c("red", "black", "green", "blue"),
             ylim=c(0,1),
             ggtheme = theme_bw(),
             xlab="Relapse Free Suvival (Days)",
             main = "Survival curve",
             pval = TRUE,
             font.x =  16,
             font.y = 16,
             font.tickslab = 14,
             font.legend =c(14,"plain","black"),
             legend = "bottom", 
             legend.title = "Tree Cluster",
             legend.labs = c("Cluster1", "Cluster2", "Cluster3", "Cluster4"), lty=1, lwd=3)
}

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of imane hajar
Sent: Friday, January 12, 2018 7:42 AM
To: r-help at r-project.org
Subject: [R] Help with packages (methods, stats, stats4)

[Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or unexpected emails.]





hello,
Can you please give me a hand with this problem,well i can't install these
packages:
- stats
- methods
- stats4

when i tried the following command :  *library(help = "stats") * , it gave me this output (*see picture*), so i contacted the Maintainer of the package at (*R-core at r-project.org <R-core at r-project.org>*) but he said that i write to the wrong place.

(i want to install those packages in order to use the "DVstats" package)

(i have the latest version of R (3.4.3 ) and Rstudio(1.2.240) )

thank you
Regards


---------------------------------------------------------------------
-SECURITY/CONFIDENTIALITY WARNING-
This message (and any attachments) are intended solely for the individual or entity to which they are addressed. This communication may contain information that is privileged, confidential, or exempt from disclosure under applicable law (e.g., personal health information, research data, financial information). Because this e-mail has been sent without encryption, individuals other than the intended recipient may be able to view the information, forward it to others or tamper with the information without the knowledge or consent of the sender. If you are not the intended recipient, or the employee or person responsible for delivering the message to the intended recipient, any dissemination, distribution or copying of the communication is strictly prohibited. If you received the communication in error, please notify the sender immediately by replying to this message and deleting the message and any accompanying files from your system. If, due to the security risks, you do not wish to receive further communications via e-mail, please reply to this message and inform the sender that you do not wish to receive further e-mail from the sender. (LCP301)
---------------------------------------------------------------------



More information about the R-help mailing list