Home > database >  Looking for an R function to divide data by date
Looking for an R function to divide data by date

Time:03-17

I'm just 2 days into R so I hope I can give enough Info on my problem. I have an Excel Table on Endothelial Cell Angiogenesis with Technical Repeats on 4 different dates. (But those Dates are not in order and in different weeks)

My Data looks like this (of course its not only the 2nd of March):

enter image description here

I want to average the data on those 4 different days, so I can compare i.e the "Nb Nodes" from day 1 to day 4. So to finally have a jitterplot containing the group, the investigated Data Point and the date.

I'm a medical student so I dont really have yet any knowledge about this kind of stuff but Im trying to learn it. Hopefully I provided enough Info!

Found the solution:

#Group by 
library(dplyr)
DateGroup <- group_by(Exclude0, Exp.Date, Group)

#Summarizing the mean in every Group and Date 
summarise(DateGroup, mymean = mean(Date$`Nb meshes`))

CodePudding user response:

I'm not sure if I understand the question, however, I think the below code will work

  1. group_by the dimension you want to summarize by

2a. across() is helper verb so that you don't need to manually type each column specifically, it allows us to use tidy select language so that we can quickly reference columns that contains "Nb" (a pattern that I noticed from your screenshot)

2b. With across(), second argument, you then use formula that you want to apply to each column from the first argument of across()

2c. Optional argument in across so that the new columns names have a name convention)

Good luck on your r learning! its a really great language and you made the right choice

#df is your data frame

df %>% group_by(Exp.Date) %>% 
  summarize(across(contains("Nb"),mean,.names = {.fn}_{.col}))

#if you just want a single column then do this
df %>% group_by(Exp.Date) %>% 
  summarize(mean_nb_nodes=mean(`Nb nodes`))

if you found this helpful please upvote or select as answer

  •  Tags:  
  • r
  • Related