Mutate usage length of column error

狂风中的少年 提交于 2019-12-08 06:27:54

问题


I'm a new R user. I've been trying to compute the time difference between two time points, and calculate a percentage value (habitual_efficiency). Using this percentage value, I need to assign specific value to a new variable (i).

time_difference1 <- as.numeric(difftime(strptime(var$psqi_1_bedtime, "%H:%M"), strptime(var$psqi_3_waketime, "%H:%M")))
timedifference <- abs (24 - time_difference1)
var4 <- data.frame (habitual_efficiency = 1: nrow(var))
transmute (var, habitual_efficiency = (var$psqi_4_sleeptime*100/timedifference))
var4 <- data.frame (comp4score = 1: nrow(var))
var4 <- var4 %>% mutate(comp4score = case_when(var$habitual_efficiency > 84.00 ~ 0, var$habitual_efficiency > 74.00 & var$habitual_efficiency <= 84.00 ~ 1, var$habitual_efficiency > 65.00 & var$habitual_efficiency <= 74.00 ~ 2, var$habitual_efficiency <= 65.00 ~ 3, TRUE ~ NaN
 )
)
var4

When I run this code, I keep getting the following error: Error in mutate_impl(.data, dots) : Column habitual_efficiency must be length 430 (the number of rows) or one, not 0 Error in mutate_impl(.data, dots) : Column i must be length 430 (the number of rows) or one, not 0

How would I approach solving this?

来源:https://stackoverflow.com/questions/50803746/mutate-usage-length-of-column-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!