R Studio For Loop错误。搜索高低

时间:2016-07-25 01:49:49

标签: r for-loop leaflet

我高低搜索找到答案,我找不到与之相关的任何内容。任何帮助将在解释导致此错误的原因时受到赞赏。提前谢谢。

 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}

但没有白费。

1 个答案:

答案 0 :(得分: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)
    }

希望它有效!