我有一个包含12个数据帧的列表。他们都有相同的结构。 其中一个看起来很方便: (每个数据帧中有9个,最后一个不能在这里显示)
X2016_kvish_1_10t
kvish keta maslul yom nefah date day_mean day_min
1 1 10 1 1 1710 2016-09-11 00:00:00 2848.375 588
2 1 10 1 1 934 2016-09-11 01:00:00 2848.375 588
3 1 10 1 1 800 2016-09-11 02:00:00 2848.375 588
4 1 10 1 1 637 2016-09-11 03:00:00 2848.375 588
5 1 10 1 1 588 2016-09-11 04:00:00 2848.375 588
6 1 10 1 1 951 2016-09-11 05:00:00 2848.375 588
7 1 10 1 1 2312 2016-09-11 06:00:00 2848.375 588
8 1 10 1 1 3769 2016-09-11 07:00:00 2848.375 588
9 1 10 1 1 3348 2016-09-11 08:00:00 2848.375 588
10 1 10 1 1 2788 2016-09-11 09:00:00 2848.375 588
11 1 10 1 1 2879 2016-09-11 10:00:00 2848.375 588
12 1 10 1 1 3318 2016-09-11 11:00:00 2848.375 588
13 1 10 1 1 3713 2016-09-11 12:00:00 2848.375 588
14 1 10 1 1 4102 2016-09-11 13:00:00 2848.375 588
15 1 10 1 1 4333 2016-09-11 14:00:00 2848.375 588
16 1 10 1 1 4583 2016-09-11 15:00:00 2848.375 588
17 1 10 1 1 4614 2016-09-11 16:00:00 2848.375 588
18 1 10 1 1 4367 2016-09-11 17:00:00 2848.375 588
19 1 10 1 1 4040 2016-09-11 18:00:00 2848.375 588
20 1 10 1 1 3766 2016-09-11 19:00:00 2848.375 588
21 1 10 1 1 3443 2016-09-11 20:00:00 2848.375 588
22 1 10 1 1 2793 2016-09-11 21:00:00 2848.375 588
23 1 10 1 1 2439 2016-09-11 22:00:00 2848.375 588
24 1 10 1 1 2134 2016-09-11 23:00:00 2848.375 588
25 1 10 1 2 1317 2016-09-12 00:00:00 2818.042 660
26 1 10 1 2 759 2016-09-12 01:00:00 2818.042 660
27 1 10 1 2 727 2016-09-12 02:00:00 2818.042 660
28 1 10 1 2 660 2016-09-12 03:00:00 2818.042 660
#...
#168 rows total
我构建了一个numburs向量,这样我就可以在每个数据帧中更改我的7列( day_mean 列),这样它就会获得NA的新值。所以我用这个函数来应用它:
aa = seq(1, 168 , 24) # the numeric vector
bb = rep(T, 168)
bb[aa] = FALSE
cc= (which(bb))
function(X) { # the function that cahnge my 7's column in each dataframe
X[,7][cc] = NA
return(X)
}
lapply(kvish_1_10t.tables, func)
到目前为止一切都很顺利,但是当我试图在多列上应用相同的功能时,它发送给我一个错误。我改变了这个功能,所以当我在这里写下来的时候,它会更新到其他列。
function(X) {
X[,7:9][cc] = NA
return(x)
{
Error in `[<-.data.frame`(`*tmp*`, cc, value = NA) :
new columns would leave holes after existing columns