Fetching the total amount of SE reputation accumulated 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&gt;101) 
    s=s+q
}
print(s)


Sample input would be a user's id, like 10400443.
It's simple to extract all reputation and subsequently sum an index. This is instead of performing the ifelse inside the *apply function to demonstrate indexing.

library(httr)
allc &lt;- content(GET(paste0("http://api.stackexchange.com/users/",'10400443',"/associated")))
allci &lt;- allc$items

# get all reputation out of list
allrep &lt;- sapply(allci,`[[`,'reputation')

# sum only index of &gt; 101
sum(allrep[allrep &gt; 101])


I'm not familiar with Python, but it appears that indexing in R serves the same purpose as list comprehension in Python - list comprehension in r