-1

I'm new to r so I'm not sure if I'll ask my own question right but I have a data frame from a study and it provided a data set:

enter image description here

that I trimmed down to what I needed to combine in the picture, I've been trying to find a way to combine each individual(e) and take the mean of each observation(w) so that I'll end up with one row for each individual and the mean of its combined observations. I know how to do this if I do it all separately with

mean(m$`30901`$deltaon)

(m is the original list) but I wanted to find a way so that it goes

mean(m$indivduals[1:40]$deltaon)

so that it will give the means for each. I've been trying to mess with for loops but I cant seem to figure it out.

lrnzcig
  • 3,868
  • 4
  • 36
  • 50
Britta
  • 1
  • 2

1 Answers1

1

we can use data.table for this problem:

         install.packages("data.table")
         library(data.table)
         m<-data.table(e,w)
         mean(m$individual[1:40]*m$deltaon)

think this will help you.

RHA
  • 3,677
  • 4
  • 25
  • 48
Sorif Hossain
  • 1,231
  • 1
  • 11
  • 18