# Resorting Nested Column Data Into Rows

#### pclayson

##### New Member
Thank you for glancing at this post!

My problem is this: I have my data currently sorted in three columns (Participant, Time, Obs). Each participant has 5 observations (in obs column) for two different time points (1 & 2; each participant has 10 total observations). I need to resort the data so that each participant has only two rows, Time 1 & Time 2, and the 5 observations for each time point are all on the same row. I have attached a sample of the dataset to help.

I have tried using the library reshape but haven't been able to get it to work. In advance, thank you very much for you help if you have any ideas.

#### Dason

I use reshape2.

You need to create an id variable to basically tell it which column the observations will be going into

Code:
dat <- read.table("~/Downloads/tempdata.txt", header = T, sep = "\t")
dat\$id <- 1:5

library(reshape2)
dcast(data = dat, formula = Participant + Time ~ id, value.var = "Obs")

#### pclayson

##### New Member
Thank you very much! You helped me last time as well. I appreciate your quick responses.