activity <- mutate(
activity, steps = ifelse(is.na(steps), lookup_mean(interval), steps))
“steps”变量从int更改为列表。我希望它保持“int”所以我可以聚合它(聚合失败,因为它是一个列表类型)。
在:
> str(activity)
'data.frame': 17568 obs. of 3 variables:
$ steps : int NA NA NA NA NA NA NA NA NA NA ...
$ date : Factor w/ 61 levels "2012-10-01","2012-10-02",..: 1 1 1 1 1 1 1 1 1 1 ...
$ interval: int 0 5 10 15 20 25 30 35 40 45 ...
后:
> str(activity)
'data.frame': 17568 obs. of 3 variables:
$ steps :List of 17568
..$ : num 1.72
..$ : num 1.72
查找平均值在此处定义:
lookup_mean <- function(i) {
return filter(daily_activity_pattern, interval == 0) %>% select(steps)
}
答案 0 :(得分:1)
问题是lookup_mean返回一个列表,因此R将活动$步骤中的每个值转换为列表。 lookup_mean应该是:
def parse(self, response):
return scrapy.Request("http://www.google.com",
callback=self.parse2,
dont_filter=True)