Since I am new to R, I have pulled this code together in kind of a rag-tag way, but I am wondering, is there something similar to list comprehensions (in Python) I can use in R to make this simpler? Or a better way of doing this? I am trying to fetch the total amount of reputation a user has accumulated on Stack Exchange. I am ideally looking for a way to remove the for
loop and use the sum
function on a subset of items (from the API response).
library(httr)
s = 0
for(i in content(GET(paste("http://api.stackexchange.com/users/",readline(),"/associated",sep="")))$items) {
q=i$reputation
if (q>101)
s=s+q
}
print(s)
Sample input would be a user's id, like 10400443
.