Skip to content

Average data with more than just id #31

@estebanbeck

Description

@estebanbeck

When you try to do an average with more than one "by" you brake the behavr object and you end up with no key.
This is the issue and a potential patch to re-attach the metadata to the resulting summary.

metadata <- data.frame(id = paste0("toy_experiment|",1:2),
                       condition = c("A", "B"))
dt_test <- toy_activity_data(metadata = metadata)
#to add day number, and light phase
dt_test [,day:=floor(t/days(1))]
dt_test [,phase:=ifelse(t %% hours(24)>hours(12),"Dark","Light")]
dt_test [,phase:=factor(phase, levels= c("Light","Dark"))]
dt_summary_test  = dt[,
                  .(var = mean(asleep))
                  ,keyby=c("id", "phase")]
dt[meta=T][dt_summary_test]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions