Question

I am using the TwitteR package in R to data-mine and I am having some trouble with accounts that follow a large amount of users.I have a list of twitter screen names which I obtained using a simple search:

smalltest<-searchTwitter("bridgegate",n=25)

Then I just replaced the list with only the screen names:

smalltest= laply(smalltest, function(t) t$getScreenName())

I wanted to limit my list of screennames to users that have less than X amount of friends which I think I can verify through the FriendsCount() function. I think I would run a loop and an if statement but I am unsure of the proper syntax to use. Something like this maybe?

 for(i in 1:length(smalltest))){
user<-getUser(smalltest[i])
if user$FriendsCOUNT >250
*some command to remove this username from smalltest*

}

The FriendsCount as far as I can tell is just a field within the user object. Not sure what the correct syntax is to access it. I realize this is a long question, any help would be greatly appreciated!!

This is the code I just tried to use, but I keep getting syntax errors.

for(i in 1:length(smalltest)) {
  user <- getUser(smalltest[i])
  numbfriends<-user$getFriendsIDs()
    if length(numbfriends) >250{
    smalltest[i] <-list(null)
  }


}
Was it helpful?

Solution

No need for a for loop, but you might want to take a look at both the twitteR package vignette in a bit more detail and also review some of the samples over at the Twitter dev site:

bridgegate <- searchTwitter("bridgegate", n = 25)

# try not to use 't' as a variable name since there's a 't()' function
bridgeTweeters <- laply(bridgegate, function(x) x$getScreenName())

# this gets us **tons** of info about all the twitter users we found above
bridgeTweeters <- lookupUsers(bridgeTweeters)

# prlby 20 other ways to do the following
bridgeTweeters.250 <- as.character(na.omit((sapply(bridgeTweeters, function(x) {
    return(ifelse((x$friendsCount <= 250), x$screenName, NA))
}))))

print(bridgeTweeters.250)

## [1] "SatireFunnyNews" "USRadioNews"     "JOBCREMATORMITT" "__Semir__"      
## [5] "TexasPolitica"   "CallMeAhmjusAyn" "FoamFingerFan"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top