如何在 twitteR R 包的 getUser 中引用變量名? (How to refer a variable name in getUser in twitteR R package?)


問題描述

如何在 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"

(by sachinvlukeA)

參考文件

  1. How to refer a variable name in getUser in twitteR R package? (CC BY‑SA 2.5/3.0/4.0)

#R #twitter






相關問題

如何將均值、標準差等函數應用於整個矩陣 (How to apply mean, sd etc. function to a whole matrix)

Tạo các thùng của mỗi hàng trong bảng và vẽ hình thanh ngăn xếp trong R (Make bins of each table row and draw stack bar figure in R)

Reading not quite correct .csv file in R (Reading not quite correct .csv file in R)

包'treemap'中的線條粗細 (Thickness of lines in Package ‘treemap’)

是否需要帶有 awk 的預處理文件,或者可以直接在 R 中完成? (Is preprocessing file with awk needed or it can be done directly in R?)

rpivotTable 選擇元素下拉菜單 (rpivotTable select elements drop down menu)

優化性能 - Shiny 中的大文件輸入 (Optimizing Performance - Large File Input in Shiny)

數值取決於所應用的應用系列,R (Numeric values depending of apply family applied, R)

如何記錄全年的值? (How to note the values across year?)

R中的線性搜索 (Linear search in R)

在 dplyr/purrr 工作流程中動態連接多個數據集 (Dynamically join multiple datasets in a dplyr/purrr workflow)

如何將行值更改為列名 (R) (How change Row values to Column names (R))







留言討論