首页 > 解决方案 > 'list' 对象不能被强制输入'integer' -- WRS2 包

问题描述

尝试使用 WRS2 包的功能时遇到以下错误。

sequence.default(piece, ...) 中的错误:不能强制“list”对象键入“integer”

下面是代码。Percentile_rank、grade_level 和 books_quantile 的数据类型是数值数据。Percentile rank 的值是 1-99,grade_level 是 1-10,books_quantile 是 1-3。每个观察结果都反映了一个学生的成绩、他们的考试成绩的百分位排名以及他们收到的书籍数量的四分位数。

library(WRS2)
pbad2way(percentile_rank~ grade_level + books_quantile + grade_level*books_quantile,
         data = read) 

数据框“读取”的快照如下(我删除了一些敏感/不相关的变量)

tibble [20,903 x 21] (S3: tbl_df/tbl/data.frame)
 $ id                    : chr [1:20903] "4886656" "4648093" "4544642" "4487743" ...
 $ school_year_key          : chr [1:20903] "2019" "2019" "2019" "2019" ...
 $ grade_key                : chr [1:20903] "736" "738" "738" "738" ...
 $ grade_level              : Factor w/ 10 levels "1","2","3","4",..: 1 3 3 3 3 3 3 3 3 4 ...
 $ percentile_rank          : num [1:20903] 43 97 84 23 27 5 84 6 1 21 ...
 $ books_count              : num [1:20903] 55 46 43 56 57 55 49 42 51 57 ...
 $ discipline               : chr [1:20903] "Reading" "Reading" "Reading" "Reading" ...
 $ books_quantile           : Factor w/ 3 levels "1","2","3": 2 2 2 3 3 2 2 2 2 3 ...

当我在错误后使用 traceback() 时,它显示如下:

8: sequence.default(piece, ...)
7: .fun(piece, ...)
6: (function (i) 
   {
       piece <- pieces[[i]]
       if (.inform) {
           res <- try(.fun(piece, ...))
           if (inherits(res, "try-error")) {
               piece <- paste(utils::capture.output(print(piece)), 
                   collapse = "\n")
               stop("with piece ", i, ": \n", piece, call. = FALSE)
           }
       }
       else {
           res <- .fun(piece, ...)
       }
       progress$step()
       res
   })(10L)
5: loop_apply(n, do.ply)
4: llply(.data = pieces, .fun = .fun, ..., .progress = .progress, 
       .inform = .inform, .parallel = .parallel, .paropts = .paropts)
3: alply(nfac1, 1, sequence)
2: unlist(alply(nfac1, 1, sequence), use.names = FALSE)
1: pbad2way(percentile_rank ~ grade_level + books_quantile + grade_level * 
       books_quantile, data = read)

标签: rlistobjecttypesinteger

解决方案


推荐阅读