如何从R中的一行中进行多行?

发布于 2025-01-31 03:08:28 字数 2656 浏览 2 评论 0原文

我目前有一个数据集,该数据集在一排中包含所有信息(如果我转置)。 The very first items in the data are actually column names:

CountryPopulationO+A+B+AB+O-A-B-AB-
Albania3,074,57932.1%31.2%14.5%5.2%6.0%5.5%2.6%0.9%
Algeria43,576,691501940.0%30.0 %15.0%4.25%6.6%2.6%2.3%1.1%
阿根廷45,479,118801748.9%2.45%3.16%0.8% 0.8%0.25%...
亚美尼亚3,021,324887029.0%29.0%46.3%46.3%12.0%5.6%5.6%2.0...4.9

% 是现在,我的表在一个单列中具有所有这些值(如果我转置,则行)。

我如何确保在每个国家 /地区有一个新的行?

我真的只是想通过找到在此之后但在这里试图这样做,我遇到了这个问题。对任何一项帮助都将不胜感激!

谢谢。

I currently have a data set that has all information within one single row (or column if I transpose). The very first items in the data are actually column names:

CountryPopulationO+A+B+AB+O-A-B-AB-
Albania3,074,57932.1%31.2%14.5%5.2%6.0%5.5%2.6%0.9%
Algeria43,576,691501940.0%30.0%15.0%4.25%6.6%2.3%1.1%
Argentina45,479,118801748.9%2.45%4.9%3.16%0.8%0.25%...
Armenia3,021,324887029.0%46.3%12.0%5.6%2.0%......

The problem is that right now, my table has all these values within ONE single column (or row if I transpose).

How can I make sure to have a new row at each country?

I'm truly just trying to web scrape the blood type distribution by country table found here but after attempting to do so, I have encountered this problem. Help on either would be appreciated!

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芯好空 2025-02-07 03:08:28

这应该起作用

library(rvest)
library(tidyverse)

baseurl=("https://en.wikipedia.org/wiki/Blood_type_distribution_by_country")
fullurl=URLencode(baseurl)
tables = read_html(fullurl) %>% 
  html_table(fill = TRUE)

df = tables[[2]]

This should work

library(rvest)
library(tidyverse)

baseurl=("https://en.wikipedia.org/wiki/Blood_type_distribution_by_country")
fullurl=URLencode(baseurl)
tables = read_html(fullurl) %>% 
  html_table(fill = TRUE)

df = tables[[2]]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文