绘制"Average"曲线集的曲线 [英] Plotting the "Average " curve of set of curves

查看:104
本文介绍了绘制"Average"曲线集的曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有n条曲线的集合,即这n条曲线中每条的点(x,y).我正在尝试绘制结果曲线"或平均曲线.即,取每个x的'n'y个坐标的平均值,并绘制结果.问题是对于n条曲线,xs不相同.我知道我可能必须进行插补或其他操作,但是我找不到在线进行此操作的例程.有人知道有人为此实现过r包,Matlab代码或C或C ++代码吗?如果没有,有什么想法如何巧妙地进行插值?谢谢!

I have a collection of n curves, that is, the points (x,y) for each of these n curves. I am trying to plot a "resultant curve" or average curve. Ie, take the average value of 'n' y coords for each x and plot the result. The problem is the xs are not the same for the n curves. I know I probably have to interpolate or something, but I couldn't find a routine to do it online. Does anyone know of an r package or a Matlab code or C or C++ code for this implemented by someone ? If not, any ideas how to go about the interpolation in a clever way ? Thanks!!

推荐答案

使用approx进行线性插值的R解决方案.

An R solution using approx for linear interpolation.

首先,我创建一些数据(您质疑一个可重复的示例). 在这里,我正在创建一个列表,该列表具有5个data.frame,具有不同的xs:

First I create some data ( you question mis a reproducible example). Here I am creating a list , with 5 data.frame, with differents xs:

ll <- lapply(1:5,function(i)
  data.frame(x=seq(i,length.out=10,by=i),y=rnorm(10)))

然后应用approx,我创建了一个包含所有数据的大data.frame:

Then to apply approx, I create a big data.frame containing all the data:

big.df <- do.call(rbind,ll)

然后,我绘制线性近似值和所有序列:

Then , I plot the linear approximation and all my series :

plot(approx(big.df$x,big.df$y),type='l')
lapply(seq_along(ll), 
       function(i) points(ll[[i]]$x,ll[[i]]$y,col=i))

这篇关于绘制"Average"曲线集的曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆