問題描述
如何在 twitteR R 包的 getUser 中引用變量名? (How to refer a variable name in getUser in twitteR R package?)
我正在使用 twitteR R 包,我在一個變量名替換的地方感到震驚。我嘗試搜索但沒有運氣。請建議您是否有任何解決方案。我本可以使用 getUser() 但需要使用 lookupUsers,因為我有多個值。
USERLIST <‑ "android"
userInfo <‑ lookupUsers(USERLIST)
userInfo$android$id
[1] "382267114"
現在我需要一種方法來在最後一個命令中調用 USERLIST 中的值,但它不起作用。
userInfo$USERLIST$id
userInfo$`USERLIST`$id
讓我知道如何進行變量替換。謝謝
參考解法
方法 1:
Assuming you got
USERLIST <‑ c("android", "StackOverflow")
userInfo <‑ lookupUsers(USERLIST)
Then you can iterate over your userInfo
list and access the id value of each user object like this:
sapply(userInfo[USERLIST], function(x) x$id)
# android StackOverflow
# "382267114" "128700677"