Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a value not a list

I have this code:

m = sapply(split(DB, DB$ID), function(grp){
grp[max(grp$Time, na.rm =T), "Score"]-
grp[min(grp$Time, na.rm=T), "Score"]
})

Basically a code to calculate difference in score variables between rows (I have long data of repeated measures).
I want to get the m as a value not as a list because I want to merge it back in the database
how can I do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use a group_by operation

library(dplyr)
DB %>%
    group_by(ID) %>%
    summarise(Score2 = Score[max(Time, na.rm = TRUE)] - 
       Score[min(Time, na.rm = TRUE)], .groups = 'drop')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading