[R] Changing sign of columns and values

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Jun 14 00:26:11 CEST 2022

Hi Hana,
The reason that I didn't answer your last request was that I couldn't
understand it. You attached a spreadsheet that had been pasted
together from other documents. Point 1 promised a formula for
calculating PRS, but didn't show it. Point 2 was similarly lacking a
symbolic formula that could be translated into R code. It was clear to
me that the original documents that had been cut and pasted into the
spreadsheet looked very much like homework assignments. As others have
told you, we avoid doing homework for posters.


On Tue, Jun 14, 2022 at 12:38 AM anteneh asmare <hanatezera using gmail.com> wrote:
> Dear, Jim I try the following codes but I got an error
> Dfm1<-data.table(Dfm1)
> # the names of the columns to be multiplied by BETA
> ID_names <- paste0("ID",4:8)
> # the names of the new columns that have been multiplied by beta
> new_ID_names <- paste0("new_",ID_names)
> ##### Now with a simple command we get the desired multiplication
> datfm[, (new_ID_names) := .SD *BETA, .SDcols = ID_names]
> datfm
> str(datfm)
> ##### The PRS for each individual can be calculated using the colSums
> function in base R:
> PRS<-Dfm1[, colSums(.SD), .SDcols = new_ID_names]

More information about the R-help mailing list