代码之家  ›  专栏  ›  技术社区  ›  Sandhya Ghildiyal

设置新计算变量的名称并使用函数赋值

  •  0
  • Sandhya Ghildiyal  · 技术社区  · 5 年前

    我正在编写一个函数,它使用来自两个数据集(RawDataSplit和Hierarchy)的引用。所有这些数据集都是连接的。我需要根据将应用于所有选定列的函数汇总数据。我正在使用 summarise_ 这样做。

    然后我将创建一个包含三个参数的函数: fav_fun(dataset,levelname,demo_var)

    dataset用于我们需要聚合的数据,在本例中是RawDataSplit

    demo_var将是从数据集“层次结构”中选择的变量之一,这将是人口统计学变量之一,如年龄。

    聚合函数:

    per_qid<-function(x){
      counts<-sum(ifelse(x==4|x==5,1,0),na.rm=TRUE
      total<-sum(ifelse(x==1|x==2|x==3|x==4|x==5,1,0),na.rm=TRUE)
      #Masking and rounding
      x<- ifelse(total<masking_criteria,NA,roundUp(counts*100/total)) )
      x 
    }
    

    fav_fun<-function(dataset,levelname,demo_var){  
      demo_var<- enquo(demo_var)
      levelname<-enquo(levelname)
      demographic<-Hierarchy[,demo_var]
      demo<-levels(demographic)
      summ_method<- paste('per_qid(',questions,')')
      summ_name<-paste0(questions,'_',demographic)
      fav <- dataset %>%
               group_by(!!levelname) %>%
               filter(status=="Complete") %>%
               filter(!!demo_var==demo[1]) %>% 
               summarise_(.dots = setNames,(summ_method,summ_name))
      fav
    }
    

    这种最有趣的事是有时会抛出不同种类的错误 总结_

    以下是数据集示例: RawDataSplit:

    structure(list(QID_1 = c(4L, 3L, 5L, 2L, 5L, 5L), QID_2 = c(4L, 
    3L, 5L, 2L, 5L, 5L), QID_3 = c(4L, 4L, 4L, 6L, 5L, 5L), mastercode_1 = c(NA, 
    NA, NA, NA, NA, NA), mastercode_2 = structure(c(1L, 1L, 1L, 1L, 
    1L, 1L), .Label = "BROLLAND", class = "factor")), row.names = c(NA, 
    -6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x00372498>)
    

    问题:

    c("QID_1", "QID_10", "QID_11")
    

    structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, 4L, 
    NA, 4L, NA, 3L, 3L, 2L, 4L, 3L, 3L, 3L, 4L, 5L, 4L, NA, NA, 3L, 
    3L, 3L, 5L, 3L, 3L, 4L, NA, 4L, 4L, 3L, 3L, 4L, 3L, 4L, 3L, 4L, 
    4L, NA, 4L, 3L, 4L, 3L, 4L, 4L, NA, 5L, 4L, 3L, 4L, 3L, 4L, 3L, 
    NA, NA, 3L, NA, 3L, 4L, 3L, 3L, NA, 4L, 4L, 4L, 4L, 3L, 4L, 3L, 
    2L, 2L, 3L, 4L, 4L, 2L, 2L, 4L, 2L, 2L, 4L, 2L, 2L, 4L, 3L, 2L, 
    3L, 4L, 4L, 3L, 4L, NA, 2L, 2L, 3L, 3L, 1L, 2L, 2L, NA, 3L, NA, 
    NA, NA, 4L, 4L, 3L, 4L, 3L, 3L, 4L, 2L, 5L, 4L, 2L, NA, 4L, 2L, 
    4L, 2L, NA, 4L, NA, 4L, 3L, 4L, 4L, 4L, 3L, 4L, NA, 3L, 3L, 3L, 
    3L, 5L, 3L, 3L, 2L, 4L, 4L, NA, 4L, NA, 3L, 3L, 4L, 5L, NA, 4L, 
    NA, 2L, 4L, NA, NA, 2L, NA, 4L, NA, NA, 4L, 4L, 4L, NA, 4L, 4L, 
    4L, 3L, 3L, 3L, 4L, 4L, 5L, 4L, 3L, 3L, 3L, 2L, 3L, 5L, 4L, 3L, 
    3L, 4L, 3L, NA, 4L, 4L, 5L, 3L, NA, 4L, NA, 3L, 3L, 3L, 4L, NA, 
    3L, 3L, NA, 4L, 3L, 4L, 3L, 3L, 4L, 4L, 3L, NA, 3L, 3L, 2L, 4L, 
    NA, 3L, 5L, NA, NA, 2L, NA, 2L, 3L, 3L, NA, 4L, NA, 5L, 2L, 4L, 
    4L, 5L, 3L, 4L, 4L, 2L, 2L, NA, 2L, 5L, 3L, 2L, 4L, 2L, 3L, NA, 
    2L, 4L, 2L, NA, 3L, NA, 2L, 5L, 3L, NA, 4L, 2L, 3L, 2L, 2L, 2L, 
    2L, NA, NA, NA, NA, NA, 4L, 5L, NA, 3L, 4L, 3L, 2L, 3L, 3L, 3L, 
    3L, 3L, 4L, 3L, NA, 3L, 4L, NA, 3L, 3L, 4L, NA, NA, 4L, NA, 3L, 
    NA, 4L, 3L, 3L, NA, NA, 3L, NA, NA, 2L, NA, 2L, 3L, 4L, 5L, 3L, 
    4L, NA, NA, 2L, 4L, 2L, 2L, 2L, 4L, 2L, NA, NA, 4L, NA, NA, 4L, 
    3L, 3L, 2L, 2L, NA, 2L, 4L, 4L, NA, 4L, NA, 3L, 3L, 1L, 4L, NA, 
    NA, 3L, 2L, 2L, NA, 2L, 5L, 4L, 2L, NA, NA, 2L, 5L, NA, NA, 3L, 
    3L, 1L, NA, 2L, 2L, 5L, NA, 4L, 3L, 4L, 2L, 2L, NA, 2L, NA, 4L, 
    NA, 4L, 2L, 4L, NA, 2L, NA, 3L, 4L, 4L, 2L, NA, NA, NA, 2L, 3L, 
    4L, 4L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 4L, 3L, 3L, 2L, 3L, 4L, NA, 
    4L, 3L, 4L, 2L, 4L, 4L, 4L, 2L, NA, 3L, NA, 3L, NA, 3L, 4L, 4L, 
    3L, 4L, 3L, 2L, 4L, 5L, 3L, 3L, NA, 3L, NA, NA, NA, NA, 2L, NA, 
    NA, NA, NA, NA, NA, 3L, NA, 2L, NA, 4L, NA, 3L, NA, NA, 3L, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, NA, 
    2L, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, 3L, NA, NA, NA, NA, 2L, NA, 2L, 2L, NA, 3L, NA, NA, NA, NA, 
    NA, NA, NA, 2L, NA, 2L, 3L, NA, 2L, NA, 2L, 3L, 3L, NA, 2L, 4L, 
    3L, NA, NA, NA, NA, NA, NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, 
    3L, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, 2L, NA, NA, 2L, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    2L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2L, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3L, 
    NA, 3L, 3L, 2L, 2L, NA, 3L, 1L, NA, NA, NA, 4L, 2L, NA, NA, NA, 
    NA, NA, 5L, NA, NA, NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, 2L, NA, NA, NA, NA, 2L, NA, NA, NA, 2L, NA, NA, 
    NA, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2L, 4L, NA, 
    NA, NA, NA, NA, 2L, 3L, 2L, 5L, NA, 2L, NA, 1L, 2L, NA, NA, 2L, 
    4L, 4L, NA, 3L, 3L, NA, 3L, 3L, NA, NA, NA, 4L, 4L, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    3L, NA, NA, 2L, NA, NA, NA, NA, 3L, 3L, NA, NA, NA, NA, NA, 3L, 
    NA, 3L, 2L, 2L, 2L, 3L, 4L, 2L, 3L, 4L, 2L, 2L, 3L, 3L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 5L, 2L, 2L, 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L, NA, 2L, 1L, 4L, NA, 4L, 
    1L, 4L, 5L, 3L, 3L, 1L, 2L, 4L, 3L, NA, 4L, 5L, 4L, 4L, 3L, 2L, 
    NA, 2L, 2L, 1L, 4L, 3L, 3L, 2L, 2L, 4L, 4L, 4L, 5L, NA, 2L, NA, 
    3L, 2L, 2L, 2L, 2L, NA, 4L, 5L, NA, NA, 3L, NA, NA, 4L, 3L, 4L, 
    3L, 4L, 4L, 3L, 4L, NA, 3L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    NA, 3L, 3L, 4L, 4L, NA, NA, NA, NA, NA, 3L, NA, NA, NA, 5L, NA, 
    5L, 3L, 4L, NA, 5L, 4L, NA, NA, 4L, 3L, 5L, NA, 3L, 3L, NA, NA, 
    4L, 2L, 2L, NA, NA, 3L, 4L, 2L, NA, 2L, 1L, 3L, NA, 3L, 4L, 1L, 
    4L, NA, NA, 5L, NA, NA, NA, 5L, NA, NA, 4L, NA, NA, NA, 4L, 4L, 
    4L, 2L, NA, NA, 3L, NA, NA, NA, NA, NA, 3L, 2L, 2L, 5L, 1L, 5L, 
    4L, 4L, 2L, 3L, 2L, NA, 3L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, NA, 2L, 
    NA, NA, 2L, 1L, NA, 1L, NA, 2L, 4L, 2L, 3L, 3L, 4L, NA, 4L, 4L, 
    3L, NA, 3L, 2L, NA, 2L, 3L, 1L, 4L, NA, 3L, NA, 3L, NA, 3L, 2L, 
    2L, 2L, 3L, 4L, 4L, 5L, 5L, 4L, NA, NA, 5L, NA, 4L, NA, 3L, 3L, 
    5L, 2L, NA, 3L, 4L, 4L, 2L, 4L, 4L, NA, 3L, 2L, 2L, 4L, 1L, 3L, 
    2L, 2L, 4L, 2L, 3L, 4L, 2L, 2L, 3L, 2L, NA, NA, 4L, 4L, NA, NA, 
    5L, NA, 5L, NA, 4L, 4L, 4L, 2L, 4L, NA, NA, 3L, 2L, 5L, 3L, 2L, 
    3L, 4L, 3L, 1L, 2L, 1L, 1L, 2L, NA, 3L, 3L, 3L, 4L, NA, 4L, NA, 
    3L, NA, 2L, 3L, NA, 2L, 1L, 3L, 4L, 4L, 3L, 1L, 2L, 1L, NA, 3L, 
    NA, 2L, 3L, 3L, 2L, 4L, 3L, 4L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 4L, 
    4L, 3L, 3L, 4L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, 3L, 4L, 3L, 3L, 
    4L, 3L, 3L, 3L, 3L, NA, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 
    1L, 3L, NA, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, NA, 2L, 2L, 2L, 
    3L, 2L, 2L, 2L, 1L, NA, 3L, 3L, NA, 3L, 2L, 4L, 3L, 3L, 2L, 3L, 
    3L, 2L, 3L, 3L, 2L, 3L, NA, 3L, 3L, 4L, 2L, 3L, 4L, 4L, 3L, 3L, 
    3L, 3L, 3L, 3L, 2L, 4L, 4L, 3L, 4L, 3L, 3L, 3L, 2L, NA, 2L, 2L, 
    3L, 3L, 2L, 4L, 3L, 4L, 4L, 4L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 4L, 
    3L, 3L, 5L, 3L, 2L, 4L, 4L, 3L, 5L, 3L, 3L, 4L, 3L, NA, 3L, 1L, 
    2L, 3L, 1L, 1L, 1L, 2L, 3L, 2L, 3L, 4L, 4L, 2L, 3L, 4L, 2L, 3L, 
    2L, 4L, NA, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 2L, 
    3L, 3L, NA, NA, NA, NA, NA, 3L, NA, 3L, NA, NA, NA, NA, 3L, NA, 
    4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, 3L, NA, 5L, 5L, NA, 
    3L, NA, NA, NA, NA, NA, NA, NA, 3L, NA, 4L, 3L, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, 4L, 4L, NA, 
    NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    4L, NA, NA, 3L, 3L, NA, 3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, 4L, NA, NA, NA, NA, 4L, 4L, 3L, 3L, NA, NA, NA, NA, 3L, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, 4L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    3L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, 4L, NA, NA, NA, NA, 3L, NA, 3L, NA, 4L, 3L, NA, NA, 
    NA, 4L, NA, 3L, NA, NA, NA, 4L, 3L, NA, NA, 3L, 3L, NA, NA, NA, 
    NA, NA, NA, 3L, NA, NA, 4L, NA, 5L, NA, NA, 4L, NA, NA, NA, NA, 
    NA, 5L, 4L, NA, 5L, NA, 2L, 2L, NA, NA, NA, NA, NA, NA, NA, NA, 
    5L, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, 5L, NA, 3L, 2L, NA, 5L, NA, NA, NA, NA, NA, NA, 
    NA, 2L, 2L, NA, 3L, NA, 4L, NA, 4L, 5L, 4L, 4L, NA, NA, 4L, NA, 
    NA, 5L, 4L, NA, NA, 3L, 5L, NA, 5L, NA, NA, NA, 3L, 3L, 5L, 5L, 
    3L, 3L, NA, 2L, 1L, 5L, 5L, NA, 4L, 5L, 5L, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, 5L, 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, NA, 4L, NA, NA, 2L, NA, 4L, 3L, NA, 3L, 3L, 4L, 
    5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 3L, 5L, 5L, 3L, 3L, 5L, 5L, 
    4L, 4L, 3L, 5L, 4L, NA, NA, 4L, NA, 3L, NA, NA, 4L, 3L, 4L, 3L, 
    3L, 1L, 3L, 2L, 3L, 5L, NA, NA, 1L, NA, 3L, NA, NA, 4L, 4L, NA, 
    NA, 3L, 2L, 3L, NA, NA, 3L, NA, 4L, 4L, 5L, NA, 4L, 3L, 5L, 5L, 
    4L, 5L, 4L, 4L, 4L, 5L, NA, 5L, 4L, 5L, NA, 4L, 3L, 4L, 4L, 4L, 
    4L, NA, 5L, NA, 5L, 5L, 2L, 5L, 4L, 4L, NA, 5L, 4L, 4L, 4L, 4L, 
    NA, 2L, NA, NA, 3L, 5L, 5L, 4L, 4L, 5L, 5L, 3L, 3L, 5L, 4L, 3L, 
    2L, 5L, 3L, 5L, 5L, 4L, 5L, 2L, 2L, 3L, 4L, 3L, 3L, 3L, 2L, 2L, 
    4L, 3L, 2L, 2L, 4L, 5L, 4L, 1L, 1L, 2L, 1L, 2L, 4L, 2L, 2L, 5L, 
    NA, 3L, 2L, 1L, 4L, 4L, 3L, 3L, 2L, 2L, 1L, 3L, 3L, NA, 3L, 3L, 
    3L, 4L, 3L, 4L, 1L, 2L, 4L, 3L, 4L, 1L, 2L, 2L, 4L, 2L, 2L, 3L, 
    2L, 5L, 5L, 3L, 5L, NA, 3L, NA, 3L, 5L, 4L, 4L, 5L, 3L, 3L, 3L, 
    4L, 3L, 3L, 4L, 5L, 4L, 4L, 4L, NA, NA, 4L, NA, 4L, 5L, 4L, 3L, 
    5L, 3L, 4L, 3L, 4L, NA, 3L, NA, 3L, 3L, NA, NA, 4L, 4L, NA, NA, 
    NA, NA, NA, NA),
    .Label = c("18 to less than 25 years old", "25 to less than 35 years old", 
    
    "35 to less than 45 years old", "45 to less than 55 years old",
    "More than 55 years old"), class = "factor")
    

    我需要一个fav_fun函数,它接受这三个参数并聚合RawDataSplit并修改名称。与QID_1一样,对于年龄变量的级别1,聚合后的新名称为QID_1_45至55岁以下

    0 回复  |  直到 5 年前