推 jackhzt: 真的很感謝大大 12/31 13:21
※ 引述《jackhzt (巴克球)》之銘言:
: [軟體程式類別]:R
: [程式問題]:其實是關於一個套件,leaflet中的問題,但是其實也沒有很相關
: 反而和for的放法比較相關
: [軟體熟悉度]:
: 熟悉
: [問題敘述]:
: [程式範例]:
: addTiles(leaflet()) %>%
: addRectangles(
: lng1=poi2(1)[1], lat1=poi2(1)[2],
: lng2=poi2(1)[1]+0.002, lat2=poi2(1)[2]+0.002,
: fillColor = "transparent"
: )
: 其中poi2是自己做的函數 就是放經度以及緯度的一個函數
: 問題是 我想要做到
: leaflet() %>% addTiles() %>%
: addRectangles(
: lng1=poi2(1)[1], lat1=poi2(1)[2],
: lng2=(poi2(1)[1]+50/10000), lat2=(poi2(1)[2]+50/10000),
: fillColor = "transparent"
: )%>%
: addRectangles(
: lng1=poi2(2)[1], lat1=poi2(2)[2],
: lng2=(poi2(2)[1]+50/10000), lat2=(poi2(2)[2]+50/10000),
: fillColor = "transparent"
: )%>% addRectangles(
: lng1=poi2(3)[1], lat1=poi2(3)[2],
: lng2=(poi2(3)[1]+50/10000), lat2=(poi2(3)[2]+50/10000),
: fillColor = "transparent"
: )%>%addRectangles(
: lng1=poi2(4)[1], lat1=poi2(4)[2],
: lng2=(poi2(4)[1]+50/10000), lat2=(poi2(4)[2]+50/10000),
: fillColor = "transparent"
: )
: 可以讓poi2(i)這函數一直自動跑嗎?
: poi2(i)中的i 可以一直自動放下去 到指定的大小
: 那麼for要掛上去 是要掛哪邊?
: 目前正在苦力朝50邁進 R光滑鼠滾輪滾下去就要當掉了
leaflet() %>% addTiles() %>% {
l_ply(1:4, function(i){
addRectangles(.,
lng1=poi2(i)[1], lat1=poi2(i)[2],
lng2=(poi2(i)[1]+50/10000), lat2=(poi2(i)[2]+50/10000),
fillColor = "transparent")
})
}
紅色的大括號是關鍵,詳情見簽名檔magrittr
--
R資料整理套件系列文:
magrittr #1LhSWhpH (R_Language) http://tinyurl.com/1LhSWhpH
data.table #1LhW7Tvj (R_Language) http://tinyurl.com/1LhW7Tvj
dplyr(上) #1LhpJCfB (R_Language) http://tinyurl.com/1LhpJCfB
dplyr(下) #1Lhw8b-s (R_Language)
tidyr #1Liqls1R (R_Language) http://tinyurl.com/1Liqls1R
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.109.74.87
※ 文章網址: https://www.ptt.cc/bbs/Statistics/M.1451537541.A.7F9.html
※ 編輯: celestialgod (140.109.74.87), 12/31/2015 13:03:10