0

我有一个文本文件(myFile.txt),我试图将其转换为 data.frame

这是一个摘录

 <li>

                    <a title="Data table: Grand Falls-Windsor (Census Agglomeration), Newfoundland and Labrador" href="../../details/page.cfm?Lang=E&amp;Geo1=CMA&amp;Code1=010&amp;Geo2=PR&amp;Code2=01&amp;Data=Count&amp;SearchText=Grand%20Falls-Windsor&amp;SearchType=Begins&amp;SearchPR=01&amp;B1=All&amp;GeoLevel=PR&amp;GeoCode=010&amp;TABID=1">Grand Falls-Windsor&nbsp;(<acronym title="Census Agglomeration">CA</acronym>)</a> [<a href="../../details/page_Map_Carte_Detail.cfm?Lang=E&amp;G=1&amp;Geo1=CMA&amp;Code1=010&amp;Geo2=PR&amp;Code2=01&amp;Data=Count&amp;SearchText=&amp;SearchType=Begins&amp;SearchPR=01&amp;B1=All&amp;Custom=&amp;TABID=1&amp;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&amp;Geo1=CMA&amp;Code1=001&amp;Geo2=PR&amp;Code2=01&amp;Data=Count&amp;SearchText=St.%20John's&amp;SearchType=Begins&amp;SearchPR=01&amp;B1=All&amp;GeoLevel=PR&amp;GeoCode=001&amp;TABID=1">St. John's&nbsp;(<acronym title="Census Metropolitan Area">CMA</acronym>)</a> [<a href="../../details/page_Map_Carte_Detail.cfm?Lang=E&amp;G=1&amp;Geo1=CMA&amp;Code1=001&amp;Geo2=PR&amp;Code2=01&amp;Data=Count&amp;SearchText=&amp;SearchType=Begins&amp;SearchPR=01&amp;B1=All&amp;Custom=&amp;TABID=1&amp;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末尾有 s 没有生效。

\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&amp;Geo1=CMA&amp;Code1=001&amp;Geo2=PR&amp;Code2=01&amp;Data=Count&amp;SearchText=St.%20John's&amp;SearchType=Begins&amp;SearchPR=01&amp;B1=All&amp;GeoLevel=PR&amp;GeoCode=001&amp;TABID=1>St. Johns&nbsp;(<acronym title="Census Metropolitan Area">CMA</acronym>)</a> [<a href="../../details/page_Map_Carte_Detail.cfm?Lang=E&amp;G=1&amp;Geo1=CMA&amp;Code1=001&amp;Geo2=PR&amp;Code2=01&amp;Data=Count&amp;SearchText=&amp;SearchType=Begins&amp;SearchPR=01&amp;B1=All&amp;Custom=&amp;TABID=1&amp;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()无论如何都是不正确的方法?

4

2 回答 2

1

看起来你可能有一个未封闭的开放式报价"

也许它只存在于您在此处复制和粘贴的内容中,还是存在于数据本身中?

于 2012-12-05T20:37:47.023 回答
1

您可以使用以下任何一种:

read.table("test.txt", sep="\n", quote="")
readLines(con=file("test.txt"))

你有一个不匹配的单引号问题。

于 2012-12-05T22:03:35.693 回答