R-Error:data_frames只能包含1d原子矢量和列表

Pra*_*nth 6 r plyr dplyr

我正在尝试应用dplyr包并使用以下函数计算数据集中每个卡号的条目数:

freq<- function(data){
  data <- complete.dupremoved[order(-complete.dupremoved$SUMMA),]
  aggregate(count ~., data=transform(complete.dupremoved,count=1), length)
  complete.dupremoved$count <-complete.dupremoved[complete.dupremoved$KLIENDIKAARDINR,]
  sample <- count(complete.dupremoved, vars = "KLIENDIKAARDINR")
  complete.dupremoved<- merge(complete.dupremoved,sample, by ="KLIENDIKAARDINR")
  return(complete.dupremoved)
}
Run Code Online (Sandbox Code Playgroud)

显示的错误是错误:data_frames只能包含1d原子向量和列表.

当我这样做:lapply(complete.dupremoved,class)

有些列是数字,因子,字符,整数.任何解决方案如何解决?调试器还提供以下内容:

function (x) 
{
    stopifnot(is.list(x))
    if (length(x) == 0) {
        x <- list()
        class(x) <- c("tbl_df", "tbl", "data.frame")
        attr(x, "row.names") <- .set_row_names(0)
        return(x)
    }
    names_x <- names2(x)
    if (any(is.na(names_x) | names_x == "")) {
        stop("All columns must be named", call. = FALSE)
    }
    ok <- vapply(x, is_1d, logical(1))
    **if (any(!ok)) {
        stop("data_frames can only contain 1d atomic vectors and lists", 
            call. = FALSE)**
    }
    n <- unique(vapply(x, NROW, integer(1)))
    if (length(n) != 1) {
        stop("Columns are not all same length", call. = FALSE)
    }
    class(x) <- c("tbl_df", "tbl", "data.frame")
    attr(x, "row.names") <- .set_row_names(n)
    x
}
Run Code Online (Sandbox Code Playgroud)

Sim*_*mon 7

出现此错误的原因是该函数正在将数据帧创建为原始数据帧中的变量.这就是这样做的:

complete.dupremoved$count <-complete.dupremoved[complete.dupremoved$KLIENDIKAARDINR,]
Run Code Online (Sandbox Code Playgroud)

将来,您可以使用此方法检查数据框,以确定每个变量的类:

sapply(your_df_here, class)
Run Code Online (Sandbox Code Playgroud)

抛开主要问题,我希望你能够按因子计算参赛作品.现有几种选择.