I am relatively new to R and want to change a dataframe I am working with from wide to tall.
The data I have right now looks something like this:
df.wide<-read.csv(header=T, text="
ID, Group, left.hemisphere.thk, right.hemisphere.thk, left.hemisphere.vol, right.hemisphere.vol, left.hemisphere.sa, right.hemisphere.sa
100, 0, 72, 55, 18, 6, 333, 22
101, 0, 73, 50, 19, 7, 332, 11
103, 0, 72, 49, 20, 1, 300, 14
200, 1, 50, 45, 8, 1, 100, 44
201, 1, 52, 52, 9, 2, 222, 18
203, 1, 50, 33, 10, 10, 100, 15")
I want to convert the data set to be long and look like the following with also creating new variable columns:
# make Hemisphere = 0 (if left) =1 (if right)
ID Group Hemisphere Brain.Data
100 0 0 72
100 0 1 55
100 0 0 18
100 0 1 6
100 0 0 333
100 0 1 22
101 0 0 73
101 0 1 50
101 0 0 19
101 0 1 7
101 0 0 332
.
.
.
.
203 1 1 15