row_count 数据未显示在 reactable 中

row_count data not showing up in reactable

我有一个包含 6 个变量的数据框(文本摘录和编码器 categories:Julie、Amy、Hannah、Mae)。

library(sjmisc)
library( reactable)
myData <- data.frame(
    stringsAsFactors = FALSE,
    id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
    Excerpt = c("Lorem ipus sed,",
                "Maecenas pharetra eleifend turpis, in volutpat enim malesuada quis. Dui",
                "Donec id magna dictum, dignissim mi eget, imperdiet nunc.",
                "Ut sed purus lorem. Aliquam sagittis ante odio, a fringilla urna luctus eu. Etiam ligu",
                "Integer eu erat faucibus, sodales ipsum quis, ultricies neque. In suscipit","Lorem ipshoncus sed,",
                "Maecenas pharetra eleifend turpis","Donec id magna dictum, dignissim",
                "Ut sed purus lorem. Aliquam",
                "Integer eu erat faucibus, sodales ipsum quis, ultricies neque. In suscipit"),
    Julie = c("I love pimento",
              "Eat more avocado","Eat more avocado","Fish are quiet pets",
              "I love pimento","I love pimento","I love pimento",
              "Eat more avocado","I love pimento","I love pimento"),
    Mae = c("I love pimento",NA,
            "I prefer cats","Fish are quiet pets","I love pimento",
            "I love pimento","Fish are quiet pets","Eat more avocado",
            "Doesn't belong","I love pimento"),
    Hannah = c("I love pimento",
               "dogs make the best pets","I prefer cats","I prefer cats",
               "I love pimento","I love pimento","I love pimento",
               "I prefer cats","I love pimento","I love pimento"),
    Amy = c("I love pimento",
            "Eat more avocado","Eat more avocado","Fish are quiet pets",
            "I love pimento","I love pimento","I love pimento",
            "Eat more avocado","I love pimento","I love pimento"))

我使用 sjmisc 包来计算编码人员将特定字符串分配给摘录的次数

# counts strings across multiple columns
myData$fish <- row_count(myData, Julie:Amy, count = "Fish are quiet pets", append = FALSE)
myData$pimento <- row_count(myData, Julie:Amy, count = "I love pimento", append = FALSE)
myData$cats <- row_count(myData, Julie:Amy, count = "I prefer cats", append = FALSE)
myData$avocado <- row_count(myData, Julie:Amy, count = "Eat more avocado", append = FALSE)
myData$dogs <- row_count(myData, Julie:Amy, count = "dogs make the best pets", append = FALSE)
myData$notBelong <- row_count(myData, Julie:Amy, count =  "Doesn't belong", append = FALSE)

当我查看 myData 时,我可以看到我现在总共有 12 个变量,我可以看到 6 个新变量中每个变量的计数,但是,当我尝试使用 reactable 查看结果时,我可以看到我创建的新列,但列中没有显示计数数据。

reactable (myData)

我怎样才能让计数数据显示在 Reactable 中? 谢谢。

您正在与 sjmisc::row_count 的作者打算使用该函数的方式作斗争,因此所有新列都被命名为“row_count”,这打败了 reactable

试试(仅使用一个例子):

myData <- row_count(myData, Julie:Amy, count = "Fish are quiet pets", var = "fish")

然后您将有一个名为 fish 的列,reactable 将正确显示它。

或者作者的意图是你这样做...

myData <- 
   myData %>% 
   row_count(Julie:Amy, 
             count = "Fish are quiet pets", 
             var = "fish", 
             append = TRUE)