我認爲下面的代碼將工作。簡而言之,我確定每個向量的密度,近似於一些已知的x值向量,將它們全部一起包含在矩陣中,然後計算彙總統計量和圖。這是你想要做的嗎?
#Make up some fake data (each column is a sample)
mat=matrix(rnorm(5000,2,0.5),ncol=50)
#Determine density of each column
dens=apply(mat, 2, density)
#Interpolate the densities so they all have same x coords
approxDens=lapply(dens, approx, xout=seq(0.1,3.5,by=0.1))
#Create your output matrix, and fill it with values
approxDens2=matrix(0, ncol=ncol(mat), nrow=length(approxDens[[1]]$y))
for(i in 1:length(approxDens)){
approxDens2[,i]=approxDens[[i]]$y}
#Determine the mean and sd of density values given an x value
mn = rowMeans(approxDens2)
stdv = apply(approxDens2,1,sd)
#pull out those x values you approx-ed things by for plotting
xx = approxDens[[1]]$x
#plot it out
plot(xx, mn, las=1, ylim=c(0,1), type='l', ylab='Density', xlab='X')
lines(xx, mn+stdv, lty=2);lines(xx, mn-stdv, lty=2)
如果包含在某些樣品[再現的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)這將是有益輸入數據,以便我們可以真正運行您的代碼。 – MrFlick