更新:来自 dput(ldf[[1]]) 的结果
没问题。这是:“A 04/18/2013 06:34:58 3D9.1C2D9F22C2”、“A 04/18/2013 06:34:58 3D9.1C2D9F22C2”、“A 04/18/2013 06:38:24 3D9.1C2DDAE977”、“A 04/18/2013 06:42:38 3D9.1C2DA0E0B5”、“A 04/18/2013 06:42:38 3D9.1C2DA0E0B5”、“A 04/18/2013 07:07: 49 3D9.1C2DD9D3CF","A 04/18/2013 07:07:49 3D9.1C2DD9D3CF")
- 问题可能在于这 4 个变量的某些行不完整。*---------------------------------------------------- ----------------------------
我从这个论坛得到了很多这个难题,但我仍然被卡住了。我正在尝试遍历 30 个数据帧的列表,这些数据帧的数据是从文本文件中读取的。在循环结束时,我不断收到一条错误消息和一个空的目标数据帧。谁能看出问题出在哪里?
以下是一些示例数据:
[73] "E 04/21/2013 14:05:01 3D9.1C2DF6F22D" "E 04/21/2013 14:05:01 3D9.1C2DF6F22D"
[75] "E 04/21/2013 14:47:54 3D9.1C2DF6F22D" "E 04/21/2013 14:47:54 3D9.1C2DF6F22D"
[[26]]
[1] "E 04/22/2013 17:07:02 3D9.1C2DDAC745" "E 04/22/2013 17:07:02 3D9.1C2DDAC745"
[3] "E 04/22/2013 17:07:02 3D9.1C2DDAC745"
[[27]]
[1] "F 04/17/2013 15:14:39 3D9.1C2D1DB26E" "F 04/17/2013 15:14:43 3D9.1C2D1DB26E"
[3] "F 04/17/2013 15:14:43 3D9.1C2D1DB26E" "F 04/17/2013 15:14:43 3D9.1C2D1DB26E"
这是我的循环代码:
new <- data.frame()
for (i in 1:length(ldf)) {
a[i] <- as.data.frame(ldf[i])
a[i] <- as.data.frame(a[i][-1,])
names(a[i]) <- "id"
c[i] <- strsplit(as.character(a[i]$id)," ")
reader[i] = sapply(c[i],function(x)x[1])
date[i] = sapply(c[i],function(x)x[2])
time[i] = sapply(c[i],function(x)x[3])
code[i] = sapply(c[i],function(x)x[4])
out[i] <- as.data.frame(cbind(reader[i],date[i],time[i],code[i]))
new <- rbind(new, out[i])
}
这是我收到的错误消息:
Error in [<-.data.frame(`*tmp*`, i,
value = list(c..A.04.17.2013.12.24.07.3D9.1C2D1DB26E....A.04.17.2013.12.24.07.3D9.1C2D1DB26E... = c(1L,
: replacement element 1 has 337 rows, need 394
谢谢!