【发布时间】:2018-08-14 07:04:34
【问题描述】:
我想通过循环遍历行和子集来拆分我的数据框
indices = (diff(Data$Time>1800))
for (i in 1:length(indices)){
if(indices[i]==TRUE){
##### I need a function to split data by row index
}}
我试过了
lst <- split(Data, as.factor(diff(Data$Time>1800)==TRUE))
但它只返回真实的行,但我想要的是在每次它面对真实时拆分。
这就是我所拥有的
Time temp
7/1/17 13:45:34 56
7/1/17 13:45:37 68
7/1/17 13:45:39 98
7/1/17 13:45:40 99
7/1/17 13:45:46 97
7/1/17 14:16:29 48
7/1/17 14:16:30 78
7/1/17 14:16:31 66
7/1/17 14:17:34 93
7/1/17 14:17:39 98
7/1/17 14:17:40 98
7/1/17 14:17:44 93
7/1/17 14:47:10 54
7/1/17 14:47:12 67
7/1/17 14:47:16 69
7/1/17 14:47:18 95
7/1/17 14:47:19 95
7/1/17 14:47:23 96
7/1/17 14:47:28 96
7/1/17 14:47:30 99
这就是我想要的
Time temp
7/1/17 13:45:34 56
7/1/17 13:45:37 68
7/1/17 13:45:39 98
7/1/17 13:45:40 99
7/1/17 13:45:46 97
Time temp
7/1/17 14:16:29 48
7/1/17 14:16:30 78
7/1/17 14:16:31 66
7/1/17 14:17:34 93
7/1/17 14:17:39 98
7/1/17 14:17:40 98
7/1/17 14:17:44 93
Time temp
7/1/17 14:47:10 54
7/1/17 14:47:12 67
7/1/17 14:47:16 69
7/1/17 14:47:18 95
7/1/17 14:47:19 95
7/1/17 14:47:23 96
7/1/17 14:47:28 96
7/1/17 14:47:30 99
是否可以通过将这些索引存储在一个向量中然后根据该向量拆分数据帧来拆分我的数据,这意味着只要行号等于我们的值“i”就拆分该行的数据帧。以便拥有多个数据帧。
【问题讨论】:
-
欢迎来到 StackOverflow!请阅读有关how to ask a good question 的信息以及如何提供reproducible example。这将使其他人更容易帮助您。