Get startedGet started for free

Linear Mixed Effects Models: Gather 'round

Again, to be able to study the diffecences between the variable of interest, that is the weight of the individual rats, and the groups as well as the change of the weight in time, we want to gather the data to a long form.

This time we need to extract the number of days as an integer variable.

This exercise is part of the course

Helsinki Open Data Science

View Course

Exercise instructions

  • Assign key as WD and value as Weight and convert the data to a long form
  • Mutate a new variable Time by extracting the number of the day from WD
  • glimpse() the data

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# dplyr, tidyr and RATS are available

# Convert data to long form
RATSL <- RATS %>%
  gather(key = "Change me!", value = "Change me!", -ID, -Group) %>%
  mutate(Time = as.integer(substr("Change me!"))) 

# Glimpse the data
glimpse(RATSL)
Edit and Run Code