【问题标题】:R-markdown error compiling with missing value on certain paragraphR-markdown 错误编译与某些段落上的缺失值
【发布时间】:2020-09-11 02:04:42
【问题描述】:

大家好,我对 R Markdown 有疑问, 我试图将下面的 R 代码编译成 pdf 文件,但问题是省略 NA 值有一些问题, 顺便说一下,我用的是tinytex。

R 版本:4.0.0

library(tidyr)
library(dplyr)
dl <- tempfile()
download.file("http://files.grouplens.org/datasets/movielens/ml-10m.zip", dl)
ratings <- read.table(text = gsub("::", "\t", readLines(unzip(dl, "ml-10M100K/ratings.dat"))),
                      col.names = c("userId", "movieId", "rating", "timestamp"))
movies <- str_split_fixed(readLines(unzip(dl, "ml-10M100K/movies.dat")), "\\::", 3)
colnames(movies) <- c("movieId", "title", "genres")
movies <- as.data.frame(movies) %>% mutate(movieId = as.numeric(levels(movieId))[movieId],
                                           title = as.character(title),
                                           genres = as.character(genres))
movielens <- left_join(ratings, movies, by = "movieId")

edx <- movielens[-test_index,]
edx <- edx %>% mutate(year = as.numeric(str_sub(title,-5,-2)))

split_edx  <- edx  %>% separate_rows(genres, sep = "\\|")

genres_popularity <- split_edx %>%
  na.omit() %>% # omit missing values
  select(movieId, year, genres) %>% # select columns we are interested in
  mutate(genres = as.factor(genres)) %>% # turn genres in factors
  group_by(year, genres) %>% # group data by year and genre
  summarise(number = n()) %>% # count
  complete(year = full_seq(year, 1), genres, fill = list(number = 0)) # add missing years/genres

我收到了这个错误:

if (any(((x - rng[1])%%period > tol) & (period - (x - rng[1])%%period) 出错 > :
需要 TRUE/FALSE 的缺失值
调用: ... dots_cols -> eval_tidy -> full_seq -> full_seq.numeric 执行停止

这实际上发生在我为 r markdon latex 安装 tinytex 和 miktex 之后,但在此之前它可以完美运行以执行。 有人知道为什么吗?

【问题讨论】:

  • 您好,欢迎来到 SO。请为您的问题提供一些背景信息。查看How to Ask 以获取提示。提供一些数据并创建great reproducible example 是一个好的开始。

标签: r r-markdown analytics


【解决方案1】:

当我重新运行您的代码并进入

edx  %>% separate_rows(genres, sep = "\\|")

我的电脑需要很长时间才能处理数据,等我回家后我会在更大的机器上尝试一下,我会尽力帮助你

【讨论】:

  • 这个错误实际上你必须更新你的 R 并加载库 dplyr 和 tidyr。很抱歉我错过了。
  • 酷,我想也许下次在你的问题中添加“sessionInfo()”会让其他人看到你的 dplyr 版本,但很高兴你把它修好了
猜你喜欢
  • 1970-01-01
  • 2021-06-27
  • 2021-11-21
  • 1970-01-01
  • 2015-08-15
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
  • 2017-05-03
相关资源
最近更新 更多