0

I'm getting a little confused. I have data in the following format (sorry, its quite ugly) that has been imported into R:

enter image description here

Anova is meant to be used like this: aov(group~measurement, data = mydata)

However, I'm struggling to get my data to fit this format. Any help would be greatly appreciated.

Kingteeb
  • 243
  • 2
  • 3
  • 8
  • This is called converting from wide to long. There are many questions here about it; see for example [Reshape data from wide to long?](http://stackoverflow.com/a/13867804/210673). – Aaron left Stack Overflow Nov 26 '13 at 02:47
  • 1
    Also, please read [this](http://stackoverflow.com/q/5963269/324364) question carefully. Screenshots of your data are one of the surest ways to **not** get any help on StackOverflow. – joran Nov 26 '13 at 03:06

2 Answers2

1

You'd probably start out by reading your data from the CSV file that you have:

df <- read.csv("FLOCKSIZES.csv")

The following example shows how you can get your data in the form you need. Please note that this example generates random data at the beginning because you haven't provided any data so far. If you were to use read.csv like in the above example, you could skip the first portion and continue right away from where the measurements are being concatenated:

# Some random data similar to what you'd get from read.csv.
numSamples <- 50
df <- data.frame(time=1:numSamples, 
                 group1=rnorm(numSamples),
                 group2=rnorm(numSamples),
                 group3=rnorm(numSamples))

# Concatenate all measurements.
measurements <- c(df$group1, df$group2, df$group3)

# Create a vector that encodes the corresponding group (1 to 3) for each measurement.
# Note: Here we assume that we have the same number of samples from every group.
groups <- do.call(c, lapply(1:3, function(i) rep(i, numSamples)))

# So that you get an idea of what these vectors look like:
print(measurements)
print(groups)

# And here we go:
aov(groups ~ measurements)
fotNelton
  • 3,844
  • 2
  • 24
  • 35
-1

Read your data in R using csv package and convert it from wide to long format with melt function from reshape2 package

annndrey
  • 1,768
  • 2
  • 20
  • 24