[R] a fast way to do my job

Yuan Chun Ding ycd|ng @end|ng |rom coh@org
Sat Aug 10 01:50:00 CEST 2024


Dear R users,

I am running the following code below,  the gem751be.rpkm is a dataframe with dim of 751 samples by 35164 variables,  73 phenotypic variables in the furst to 73rd column and 35091 genomic variables or genes in the 74th to 35164th columns.  What I need to do is to calculate the residuals for each gene using the simple linear regression model of genelist[i] ~ purity2;

The following code is running,  it takes long time, but I have an expensive ThinkStation window computer.
Can you provide a fast way to do it?

Thank you,

Ding

---------------------------------------------------------------------------------


gem751be.rpkm <-merge(gem751be10, as.data.frame(t(rna849.fpkm2)),
+                           by.x="id2",by.y=0)
>   row.names(gem751be.rpkm)<-gem751be.rpkm$id3
>   colnames(gem751be.rpkm)<-gsub(colnames(gem751be.rpkm),pattern="-",replacement="_")
>   genelist <- gem751be.rpkm %>% dplyr::select(74:35164)
>   residuals <- NULL
>   for (i in 1:length(genelist)) {
+     #i=1
+     formula <- reformulate("purity2", response=names(genelist)[i])
+     model <- lm(formula, data = gem751be.rpkm)
+     resi <- as.data.frame(residuals(model))
+     colnames(resi)[1]<-names(genelist)[i]
+     resi <-as.data.frame(t(resi))
+     residuals <- rbind(residuals, resi)
+   }



----------------------------------------------------------------------
------------------------------------------------------------
-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)
------------------------------------------------------------

	[[alternative HTML version deleted]]



More information about the R-help mailing list