- unite, gather separate tidyr:
library(tidyr)
long <- mydata %>% unite("times1", hippLeft_T1,hippRight_T1) %>%
unite("times2", hippLeft_T2,hippRight_T2) %>%
unite("times3", hippLeft_T3,hippRight_T3) %>%
gather("times","Hipp",times1:times3) %>%
separate(Hipp,c("Left","Right")) %>%
gather("Side","Hipp",Left:Right)
:
unite T1, T2 T3 times1, times2 times3gather , times Hippseparate Hipp Left Rightgather Left Right, Side Hipp
- gather, :
library(tidyr)
long <- mydata %>% unite("Left", hippLeft_T1,hippLeft_T2,hippLeft_T3) %>%
unite("Right", hippRight_T1,hippRight_T2,hippRight_T3) %>%
gather("Side","Hipp",Left:Right) %>%
separate(Hipp,c("times1","times2","times3")) %>%
gather("times","Hipp",times1:times3)
, gather:
library(dplyr)
library(tidyr)
long <- mydata %>% gather("Side","Hipp",-SID) %>%
mutate(times=paste0("times",sub(".*(\\d)$","\\1",Side)),
Side=sub("^hipp([A-z]+)_T.*","\\1",Side)) %>%
select(SID,Side,times,Hipp)
Side gather , mydata. deployer::mutate times. sub , times Left, Right Side.
123, :
set.seed(123)
mydata <- data.frame(SID=sample(1:150,400, replace=TRUE), hippLeft_T1=sample(6000:8000,400,replace=TRUE), hippRight_T1=sample(6000:8000,400,replace=TRUE),hippLeft_T2=sample(6000:8000,400,replace=TRUE), hippRight_T2=sample(6000:8000,400,replace=TRUE),hippLeft_T3=sample(6000:8000,400,replace=TRUE), hippRight_T3=sample(6000:8000,400,replace=TRUE))
head(mydata)
:
print(long)
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#