【发布时间】:2014-03-21 16:37:41
【问题描述】:
我有一个表格,其中包含优化算法的结果。我有 100 次跑步。 X 表示时间并且仅在存储改进时存储。所以我缺少 x-es。
x1; y1 ; x2 ; y2
1 ; 100 ; 1 ; 150
4 ; 90 ; 2 ; 85
7 ; 85 ; 10 ; 60
10; 80 ;
这只是一个 csv。我正在寻找一种轻松处理此问题的方法。想要计算每个 x 值的平均值。因此,x = 4 处的平均值需要考虑到运行 2,4 处的 y 为 85。
使用 excel 的任何简单方法。或者用java或R读它? (我将使用 R 的 ggplot 绘制年龄)。
所以预期的输出应该是这样的:
x1; y1 ; x2 ; y2
1 ; 100 ; 1 ; 150
2 ; 100 ; 2 ; 85
4 ; 90 ; 4 ; 85
7 ; 85 ; 7 ; 85
10; 80 ;10 ; 60
--更新
我在下面应用了 agstudy 的答案。这是我的脚本:
library(ggplot2)
library(zoo)
data1 = read.table("rundata1", sep= " ", col.names=c("tm1","score1","current1"))
data2 = read.table("rundata1", sep= " ", col.names=c("tm2","score2","current2"))
newdata<- merge(data1[,1:2],data2[,1:2],by=1,all=T)
newdata <- newdata[!is.na(newdata$tm1),]
newdata$score1 <- zoo::na.locf(newdata$score1)
newdata$score2 <- zoo::na.locf(newdata$score2)
现在几乎可以工作了。只有一个错误:
newdata$score2 <- zoo::na.locf(newdata$score2)
Error in `$<-.data.frame`(`*tmp*`, "score2", value = c(40152.6, 40152.6, :
replacement has 11767 rows, data has 11768
【问题讨论】:
-
你能澄清一下预期的输出吗?
-
对不起,你是对的。我在问题中添加了一个示例输出。
标签: java r excel pivot-table data-mining