-3

I have a data table called "vsample2.csv" that looks like this:

vsample2

I need it to look like this in a new data table that I would create:

answer

Tried with dcast but doesn't seem to work. I don't want a function. Just a line or two.

I need to do a repeated measures anova with the data. E & H being variable level 1 and C & IC being variable level 2. I need the significance values of the variable level 1, 2 and then their interaction.

Data

set.seed(1)
dd <- data.frame(
  subject = paste('Subject', rep(1:4, each = 4)),
  lang = rep(c('H', 'E'), each = 2),
  resp = c('C', 'IC'),
  p = runif(16),
  stringsAsFactors = FALSE
)
Uwe
  • 41,420
  • 11
  • 90
  • 134

1 Answers1

2

If you just want to reshape the data try this:

library(data.table)
set.seed(1)
dd <- data.frame(
  subject = paste('Subject', rep(1:4, each = 4)),
  lang = rep(c('H', 'E'), each = 2),
  resp = c('C', 'IC'),
  p = runif(16),
  stringsAsFactors = FALSE
)
setDT(dd)
out <- dcast(dd, formula = subject~lang+resp)

Which produces:

> out
     subject       E_C      E_IC       H_C       H_IC
1: Subject 1 0.5728534 0.9082078 0.2655087 0.37212390
2: Subject 2 0.9446753 0.6607978 0.2016819 0.89838968
3: Subject 3 0.2059746 0.1765568 0.6291140 0.06178627
4: Subject 4 0.7698414 0.4976992 0.6870228 0.38410372
  • Hello Kristoffer, thanks for the response. I need to do a two way repeated measures ANOVA actually. E & H being independent variable 1 and C & IC being independent variable 2. I only attached the sample for 4 subjects. There are hundred more actually. – Venkat Kaushik Mar 19 '17 at 16:17