【发布时间】:2014-06-29 06:30:18
【问题描述】:
我有一个名为 cpue 的数据集,有 330 万行。我制作了这个数据框的一个子集,称为 dat.frame。 (请参阅下面的 cpue 和 dat.frame 的负责人。)我在 dat.frame 中添加了两个新字段:“ssh_vec”和“ssh_mag”。虽然 cpue 和 dat.frame 的头部看起来一样,但其余的行实际上并没有相同的顺序。
head(cpue)
code event Lat Long stat_area Day Month Year id
1 BCO 447602 -43.45 182.73 49 17 3 1995 1
head(dat.frame)
code event Lat Long stat_area Day Month Year id cal.jdate ssh_vec ssh_mag
1 BCO 447602 -43.45 182.73 49 17 3 1995 1 2449857 56.83898 4.499350
目前,我正在运行一个循环,使用唯一标识符“id”将 ssh_vec 和 ssh_mag 变量添加到“cpue”:
cpue$ssh<- NA
cpue$sshmag<- NA
for(i in 1:nrow(dat.frame))
{
ndx<- dat.frame$id[i]
cpue_full$ssh[ndx]<- dat.frame$ssh_vec[i]
cpue_full$sshmag[ndx]<- dat.frame$ssh_mag[i]
}
这已经在周末运行了,只到:
i
[1] 132778
...出自:
nrow(dat.frame)
[1] 2797789
在循环中,没有什么看起来对计算要求太高。有没有更好的选择?
【问题讨论】:
-
你的
sessionInfo()$platform是什么? -
"x86_64-w64-mingw32/x64(64 位)"