我有一个文本文件(myFile.txt),我试图将其转换为data.frame
这是摘录
<li>
<a title="Data table: Grand Falls-Windsor (Census Agglomeration), Newfoundland and Labrador" href="../../details/page.cfm?Lang=E&Geo1=CMA&Code1=010&Geo2=PR&Code2=01&Data=Count&SearchText=Grand%20Falls-Windsor&SearchType=Begins&SearchPR=01&B1=All&GeoLevel=PR&GeoCode=010&TABID=1">Grand Falls-Windsor (<acronym title="Census Agglomeration">CA</acronym>)</a> [<a href="../../details/page_Map_Carte_Detail.cfm?Lang=E&G=1&Geo1=CMA&Code1=010&Geo2=PR&Code2=01&Data=Count&SearchText=&SearchType=Begins&SearchPR=01&B1=All&Custom=&TABID=1&geocode=010" title="Map: Grand Falls-Windsor (Census Agglomeration), Newfoundland and Labrador">map</a>]
</li>
<li>
<a title="Data table: St. John's (Census Metropolitan Area), Newfoundland and Labrador" href="../../details/page.cfm?Lang=E&Geo1=CMA&Code1=001&Geo2=PR&Code2=01&Data=Count&SearchText=St.%20John's&SearchType=Begins&SearchPR=01&B1=All&GeoLevel=PR&GeoCode=001&TABID=1">St. John's (<acronym title="Census Metropolitan Area">CMA</acronym>)</a> [<a href="../../details/page_Map_Carte_Detail.cfm?Lang=E&G=1&Geo1=CMA&Code1=001&Geo2=PR&Code2=01&Data=Count&SearchText=&SearchType=Begins&SearchPR=01&B1=All&Custom=&TABID=1&geocode=001" title="Map: St. John's (Census Metropolitan Area), Newfoundland and Labrador">map</a>]
</li>
df <- read.table("myFile.txt",sep="\n")
这可以直到大瀑布提取物的末尾,但是\n
似乎没有生效。这是一行控制台读数,你可以看到最后有\n
个没有生效。
\t\t\t\t\t\t<a title=Data table: St. John's (Census Metropolitan Area), Newfoundland and Labrador href=../../details/page.cfm?Lang=E&Geo1=CMA&Code1=001&Geo2=PR&Code2=01&Data=Count&SearchText=St.%20John's&SearchType=Begins&SearchPR=01&B1=All&GeoLevel=PR&GeoCode=001&TABID=1>St. Johns (<acronym title="Census Metropolitan Area">CMA</acronym>)</a> [<a href="../../details/page_Map_Carte_Detail.cfm?Lang=E&G=1&Geo1=CMA&Code1=001&Geo2=PR&Code2=01&Data=Count&SearchText=&SearchType=Begins&SearchPR=01&B1=All&Custom=&TABID=1&geocode=001" title="Map: St. Johns (Census Metropolitan Area), Newfoundland and Labrador>map</a>]\n\t\t\t\t\t\n </li>\n\t\t\t \n
为此演示文稿道歉,但在尝试从控制台复制时Rstudio崩溃时遇到了很多麻烦
有人可以帮忙吗?也许read.table()
无论如何都不正确?
答案 0 :(得分:1)
看起来你可能有一个未公开的公开引用"
也许这只是你在这里复制和粘贴的内容,还是数据本身?
答案 1 :(得分:1)
您可以使用以下任何一种:
read.table("test.txt", sep="\n", quote="")
readLines(con=file("test.txt"))
您的单引号问题不匹配。