2016-07-25 72 views
0

我搜索了很高和低找到答案,我找不到與之相關的任何內容。任何幫助將不勝感激解釋什麼導致這個錯誤。提前致謝。R Studio For Loop錯誤。搜索高低

tabledata3<-getSQL("SELECT LONGITUDE,LATITUDE,SESSION,asd FROM ABC") 
leaflet(subzone) %>% 
    addTiles() %>% 
    addMarkers(data = tabledata1, lng = ~ LONGITUDE, lat = ~ LATITUDE, popup = ~ S_ID, clusterOptions = markerClusterOptions(), icon = ~markerList["before"])%>% 
    addMarkers(data = tabledata2, lng = ~ LONGITUDE, lat = ~ LATITUDE, popup = ~ S_ID, clusterOptions = markerClusterOptions(), icon = ~markerList["after"])%>% 
    for (i in tabledata3$SESSION){ 
    addPolylines(data = tabledata3, lng = ~LONGITUDE, lat = ~LATITUDE, group = ~asd , color = "black", weight = 10) 
    } 

錯誤:

Warning: Error in for: 4 arguments passed to 'for' which requires 3 

編輯的說法,也沒有試圖充分

for(i in 1:nrow(tabledata3)){ 
method} 

但沒有白費。

+0

在循環結尾做什麼'%>%'?另外,我沒有看到你實際上正在使用循環變量'i' ...爲什麼甚至有一個循環? –

+0

我刪除了%>%,並且出現同樣的錯誤。我需要循環繪製多個分離的多段線。否則,所有的座標將連接在一起。 –

+0

呃,對不起,但聲明中的4個參數是什麼?是不是隻有3? int i,1:和tabledata3中的行數。 –

回答

0

我有同樣的問題,它工作時,我把環圍繞着整個單張功能:

tabledata3<-getSQL("SELECT LONGITUDE,LATITUDE,SESSION,asd FROM ABC") 

leaflet(subzone) %>% 
     addTiles() %>% 
     addMarkers(data = tabledata1, lng = ~ LONGITUDE, lat = ~ LATITUDE, popup = ~ S_ID, clusterOptions = markerClusterOptions(), icon = ~markerList["before"])%>% 
     addMarkers(data = tabledata2, lng = ~ LONGITUDE, lat = ~ LATITUDE, popup = ~ S_ID, clusterOptions = markerClusterOptions(), icon = ~markerList["after"]) 

for(i in 1:nrow(tabledata3)){ 
    session_i <- tabledata3$SESSION[i,] 
    leaflet(subzone) %>% 
    addPolylines(data = session_i, lng = ~LONGITUDE, lat = ~LATITUDE, group = ~asd , color = "black", weight = 10) 
    } 

希望工程!