2013-11-26 24 views
0

我有点困惑。我在下面的格式数据(对不起,其相当难看),其已经导入到R:如何使用此格式的数据在R中执行ANOVA测试?

enter image description here

方差是指这样使用: AOV(组〜测量,数据= MYDATA)

但是,我努力让我的数据适合这种格式。任何帮助将不胜感激。

+0

这称为从宽转换为long。这里有很多问题。请参阅例如[重新整形数据从广泛到长?](http://stackoverflow.com/a/13867804/210673)。 – Aaron

+1

另外,请仔细阅读[this](http://stackoverflow.com/q/5963269/324364)问题。你的数据截图是最好的方法之一**不**获得对StackOverflow的任何帮助。 – joran

回答

1

你可能从你有CSV文件中读取数据开始了:

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

下面的示例演示了如何在您需要的形式让您的数据。请注意,这个例子一开始就产生了随机数据,因为到目前为止还没有提供任何数据。如果你在上面的例子中使用read.csv一样,你可以跳过第一部分,并继续从测量是串接在那里的时候了:

# 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) 
-1

使用CSV包阅读R中的数据并将其从广角转换从reshape2包到long格式的熔化函数

+0

这是一条评论,而不是答案。 – Thomas

相关问题