head(CR1)
Subject HourNominal Concentration Cohort FS EF VTI deltaFS deltaEF deltaVTI
1 005-010 0.00 NA 1 30.87 65.48 21.59 0 0 0
2 005-010 0.25 31.00 1 31.82 64.86 0.00 3 -1 -100
4 005-010 1.00 9.69 1 26.13 69.11 0.00 -15 6 -100
7 005-010 3.00 3.26 1 29.89 60.99 23.49 -3 -7 9
12 005-010 24.00 1.52 1 29.67 57.18 22.17 -4 -13 3
13 005-010 48.00 1.23 1 35.41 56.70 20.85 15 -13 -3
我想使用这个功能
organizeR = function(x, y) {
g1 = aggregate(y[,x], by=list(y[,'HourNominal']), FUN=mean)
g1 = setNames(g1, c('HourNominal', 'Function'))
g2 = aggregate(y[,x], by=list(y[,'HourNominal']), FUN=sd)
g2 = setNames(g2, c('HourNominal', 'SD'))
g1[,'SD'] = g2$SD
g1$top = g1$Concentration + g1$SD
g1$bottom = g1$Concentration - g1$SD
return(g1)
}
CRA1 = organizR(' FS',CR1)
$<-.data.frame
(*tmp*
,&#34; top&#34;,value = numeric(0))出错:
替换有0行,数据有9个
为什么替换有0行?每当我在自定义函数之外执行它时,它都可以工作,所以它应该在函数中工作。
aggregate(CR1[,'FS'], by=list(CR1[,'HourNominal']), FUN=mean)
Group.1 x
1 0.00 32.40375
2 0.25 31.52125
3 1.00 34.24000
4 3.00 32.48750
5 24.00 35.20375
6 48.00 34.80375
7 96.00 36.15500
8 216.00 35.76571
9 648.00 33.53000
aggregate(CR1[,'FS'], by=list(CR1[,'HourNominal']), FUN=sd)
Group.1 x
1 0.00 3.810534
2 0.25 4.993211
3 1.00 6.061989
4 3.00 4.105341
5 24.00 6.814786
6 48.00 4.587701
7 96.00 6.314292
8 216.00 4.434794
9 648.00 2.968451