我有一个包含6个变量的数据框(文本摘录和编码器类别:朱莉,艾米,汉娜,湄)。
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中? 谢谢。
答案 0 :(得分:0)
您正在与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)