过滤后用空零替换空单元格

时间:2018-04-03 11:16:31

标签: r dplyr

我尝试将空单元格替换为不同列中的零,而不是使用$("#itemtarget").find("input[attrValue != '']").each(function () { //code here }); 使用filter的列。例如,

dplyr

我认为temp %>% filter(Publication.type == "Link") %>% # ** Insert function or 2 to replace NAs by zeroes in another column, say Clicks_30min ** 功能在这里不起作用,也不替换。也可以选择其他解决方案。 mutate_at会工作吗?我尝试了mutate并且它犯了一个错误。

1 个答案:

答案 0 :(得分:2)

我们可以做到

temp %>% 
   filter(Publication.type == "Link") %>%
   mutate_all(funs(replace(., .=="", 0)))

如果空单元格为NA,则

temp %>% 
   filter(Publication.type == "Link") %>%
   mutate_all(funs(replace(., is.na(.), 0)))