2015-07-10 23 views
0

我想在R中導入日曆日期。 我找到了一個網站,其日期是我用XML導入的。從網絡rbind日曆數據 - 列表錯誤

library('XML') 
u="http://www.timeanddate.com/calendar/custom.html?year=2015&country=5&typ=0&display=2&cols=0&hol=0&cdt=1&holm=1&df=1" 

tables = readHTMLTable(u) 

擺脫一些不必要的元素

tables = tables[-1] 
tables = tables[-1] 
tables = tables[-13] 

生成列表名稱

names(tables) <- paste('month', 1:12, sep = '') 

a solution proposed here

mtables = mapply(cbind, tables, 'Month'= 1:12, SIMPLIFY=F) 

這裏的時候,我想我的rbind清單:

do.call('rbind', mtables) 

我得到一個錯誤:

Error in match.names(clabs, names(xi)) :
names do not match previous names

了,你能解決這個誤差問題幫助嗎?

+0

@PierreLafortune - 它不工作以重現該示例? – giacomo

回答

1

rbind通常需要兩個參數。 這是一個使用rbind的代碼片段。 希望這有助於。 歡呼 奧利弗

vehicles1 <- unique(grep("Vehicles", SCC$EI.Sector, ignore.case = TRUE, value = TRUE)) 
vehicles <- SCC[SCC$EI.Sector %in% vehicles1, ]["SCC"] 

# Select observations relating to Baltimore MD 
vehiclesBaltimore <- NEI[NEI$SCC %in% vehicles$SCC & NEI$fips == "24510",] 

# Select observations relating to Los Angeles County CA 
vehiclesLosAngelesCounty <- NEI[NEI$SCC %in% vehicles$SCC & NEI$fips == "06037",] 

# Merge observations of Baltimore and Los Angeles County 
vehiclesCompare <- rbind(vehiclesBaltimore, vehiclesLosAngelesCounty) 
+0

謝謝,但我想我找到了問題 - 它是'header == F' – giacomo

0

這個問題實際上是在header

`tables = readHTMLTable(u, header = F)` 

代替

`tables = readHTMLTable(u, header = T)` 

爲了獲得每個列表中的列名相同。

謝謝