【问题标题】:In R, Print the country with the highest population density in the dataframe在 R 中,打印数据框中人口密度最高的国家
【发布时间】:2021-06-03 07:56:07
【问题描述】:
https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/CSV_FILES/WPP2019_TotalPopulationBySex.csv

我想打印人口密度最高的国家以及该数据库的数据框中给出的该国家/地区的所有详细信息。也只有2020的数据

我该怎么做?

【问题讨论】:

  • df[df$PopDensity==max(df$PopDensity[df$Time==2020]),] 做你的工作(df 是数据集)?
  • 我一直需要这个答案。谢谢。

标签: r dataframe datatable


【解决方案1】:

这样好吗?

data=read.csv('https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/CSV_FILES/WPP2019_TotalPopulationBySex.csv', header = T)
a= unique(data[data$PopDensity==max(data[data$Time==2020,'PopDensity']),'Location'])
print(a)
view(data[data$Location==a&data$Time==2020,])

【讨论】:

  • 对不起,它不起作用。我认为,fread 有问题。我需要补充一点。我从我的电脑导入数据库,因为 r studio 没有任何反应,因为这个数据库非常大,当我写这个 url 时
  • 可能是因为 fread 函数来自 dat.table 包并且它没有加载到您的 rstudio 中。也许在之前添加library(data.table)(必要时安装包
  • install.packages 中的警告:无法创建目录“C:\Users\lenovo\Documents\R\win-library\4.0\file3f00171f10c4”,原因是“没有这样的文件或目录”错误在 install.packages 中:无法创建临时目录 'C:\Users\lenovo\Documents\R\win-library\4.0\file3f00171f10c4' 我在安装包时收到此警告。我什至无法安装 ggplot2
  • 这很奇怪哈哈它对所有包都做这样的事情吗?
  • 不幸的是,是的。我在所有网站上都对此进行了研究,但我无法解决
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多