【问题标题】:How to display the total number of a coloumn and the percentage of a coloumn [closed]如何显示一列的总数和一列的百分比[关闭]
【发布时间】:2021-01-08 21:11:05
【问题描述】:

我需要显示以下内容:

  1. 列表总数 - 给出列表,我需要从中找到总数
  2. 未审核的列表百分比:已给出列表,未审核的条目标记为 NA。

最后,我需要将这两个变量(列表总数、列表百分比)添加到一个数据框并显示。

最适合使用的 R 脚本代码是什么?

【问题讨论】:

  • 欢迎堆栈溢出。展示您的尝试和可重复的示例是一个好主意。

标签: r count display percentage rscript


【解决方案1】:

创建示例数据框:

listings <- c("Listing_1", "Listing_2", "Listing_3", "Listing_4", "Listing_5")
reviews <- c("Good", "Very Good", "Bad", NA, "Very Bad")

df <- data.frame(listings, reviews)

列表数量:

dim(df)[1]

缺失评论的百分比:

sum(is.na(df["reviews"])) / dim(df)[1] * 100

【讨论】:

    猜你喜欢
    • 2022-11-03
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多