【发布时间】:2011-06-09 09:39:14
【问题描述】:
我正在尝试创建一个循环以从先前创建的数组中提取数据,以便我可以使用提取的数据生成线图。
到目前为止,我一直在使用:
allweek1<-(data.frame(t_weekmean[,,1])) #which selects the date and generates the data frame I want to later format the date using
week1<-stack(allweek1) #and then plot it using
plot(week1$values,type="n", xlim=c(0,2),xlab="Weight (gr)",ylab="Rate (umol/L*gr)",main="All individuals and Treatments at all times")
lines(week1$values[week1$ind=="X9"]~x,type="o",col="red")
lines(week1$values[week1$ind=="X12"]~x,type="o",col="blue")
lines(week1$values[week1$ind=="X15"]~x,type="o",col="green")
lines(week1$values[week1$ind=="X18"]~x,type="o",col="purple").
我知道必须有一种方法可以将它变成一个循环,对于这个例子,我只给了两个星期,但我的数据会增加到 30,手动执行会很混乱,很容易出错。
这是我拥有的起始数组:
, , Week = 1
Temp
variable 9 12 15 18
X0 100.000 100.000 100.000 100.000
X0.5 98.855 98.591 98.357 99.003
X1 98.004 97.804 97.638 98.299
X1.5 95.953 96.999 96.810 97.555
X2 95.235 96.078 95.346 96.665
, , Week = 2
Temp
variable 9 12 15 18
X0 100.000 100.000 100.000 100.000
X0.5 99.137 99.035 97.883 99.055
X1 98.420 98.298 96.459 97.765
X1.5 97.939 97.181 94.406 96.546
X2 96.998 96.237 91.906 95.263
以下数据帧随后被转换为堆栈版本:
X9 X12 X15 X18
X0 100.000 100.000 100.000 100.000
X0.5 98.855 98.591 98.357 99.003
X1 98.004 97.804 97.638 98.299
X1.5 95.953 96.999 96.810 97.555
X2 95.235 96.078 95.346 96.665
然后使用绘图代码。
【问题讨论】: