我正在尝试从位于以下网址的XML中读取:https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml
我在R中收到以下错误:
Error: XML content does not seem to be XML: 'https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml'
Run Code Online (Sandbox Code Playgroud)
我的代码:
install.packages("XML")
library(XML)
fileURL = "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml"
doc = xmlTreeParse(fileURL)
Run Code Online (Sandbox Code Playgroud)
我想阅读那个XML文件并找出有多少家餐馆有邮政编码21231?
谢谢
尝试下载xml文件:
library(XML)
fileURL <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml"
download.file(fileURL, destfile=tf <- tempfile(fileext=".xml"))
doc <- xmlParse(tf)
zip <- xpathSApply(doc, "/response/row/row/zipcode", xmlValue)
sum(zip == "21231")
# [1] 127
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3630 次 |
| 最近记录: |