这实际上是上一个问题的延续:
很抱歉再次经历第一部分。相信我,我试图解决自己!
所以一些样本数据:
mydf<- data.frame(c("a","a","b","b","c","c"),c("e","e","e","e","e","e")
,as.numeric(c(1,2,3,10,20,30)),
as.numeric(c(5,10,20,20,15,10)))
给一些名字:
colnames(mydf)<-c("Model", "Class","Seconds", "Speed")
这使:
> mydf
Model Class Seconds Speed
1 a e 1 5
2 a e 2 10
3 b e 3 20
4 b e 10 20
5 c e 20 15
6 c e 30 10
现在最初我需要对这些数据进行样条化,答案如下:
library("plyr")
ddply(mydf, .(Model), summarise, Spline = spline(x = Seconds, y = Speed))
这导致:
Model Spline
1 a 1.0, 1.2, 1.4, 1.6, 1.8, 2.0
2 a 5, 6, 7, 8, 9, 10
3 b 3.0, 4.4, 5.8, 7.2, 8.6, 10.0
4 b 20, 20, 20, 20, 20, 20
5 c 20, 22, 24, 26, 28, 30
6 c 15, 14, 13, 12, 11, 10
顺便说一句,我什至无法在 R 中手动创建这个确切的结构,以便提供一个示例,即使是手动!
所以回到这个问题。我需要更改结果,使它们看起来像这样:
Model Seconds Speed
a 1.0 5
a 1.2 6
a 1.4 7
a 1.6 8
a 1.8 9
a 2.0 10
b 3.0 20
b 4.4 20
b 5.8 20
b 7.2 20
b 8.6 20
b 10.0 20
c 20 15
c 22 14
c 24 13
c 26 12
c 28 11
c 30 10
谢谢你的帮助!