0

我想从网页上的文本文件中保存数据并将其加载到 R 中。我遇到了一些麻烦,因为当我右键单击无法导入的数据时,我只能“将链接另存为 html”。理想情况下,我应该能够“另存为”一个正确的文本文件并使用 read.table() 加载到 R 中。

网页上的数据如下所示: 在此处输入图像描述

否则,当我尝试复制并粘贴到 Excel 中时,它无法识别这些列。

我很确定在过去右键单击数据会显示“另存为”,列出文件格式的各种选项。但是,这一次我无法使用 .html 以外的格式保存数据。

提前致谢。

运行代码后的数据头:

data=read.delim('https://wattlecourses.anu.edu.au/pluginfile.php/2439477/mod_resource/content/1/yieldfert.txt', header = F,stringsAsFactors = F)
head(data)

在此处输入图像描述

运行代码后的输出和错误:

> data1=read.table("https://wattlecourses.anu.edu.au/pluginfile.php/2439477/mod_resource/content/1/yieldfert.txt", quote = "")
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 1 did not have 5 elements
4

1 回答 1

0

你可以试试这个:

my_data <- read.delim("http://www.sthda.com/upload/boxplot_format.txt", header = F)
head(my_data)

我添加header = F是因为您的示例中的标题仅包含两个元素(yieldfert)。

于 2020-07-27T11:16:17.947 回答