我有一個問題構建一個循環,通過追加循環的結果給我一個表。我怎樣才能用append和loop構造一個表?
現在它正在水平添加列(變量),而不是垂直添加行。
可能追加不正確的功能?或者有沒有辦法讓它垂直追加? 也許我只是覺得我在製作一張桌子,但實際上是其他的一些結構呢?
我找到的解決方案使用rbind,但我沒有弄清楚如何使用rbind函數設置循環。
for (i in 1:3) {
users.humansofnewyork = append(users.humansofnewyork, getPost((humansofnewyork$id[i]) , token, n = 500, comments = TRUE,likes = TRUE, n.likes=500, n.comments=500))
}
非常感謝您的回覆。不幸的是,沒有任何解決方案奏效。
這就是全碼:
#start the libaries
library(Rfacebook)
library(Rook)
library(igraph)
#browse to facebook and ask for token
browseURL("https://developers.facebook.com/tools/explorer")
token <- "...copy and paste token"
#get Facebook fanpage "humansofnewyork" with post id
humansofnewyork <- getPage("humansofnewyork", token, n=500)
users.humansofnewyork = c()
for (i in 1:3) {
users.humansofnewyork = append(users.humansofnewyork, getPost((humansofnewyork$id[i]) , token, n = 500, comments = TRUE,likes = TRUE, n.likes=500, n.comments=500))
}