lundi 5 décembre 2016

R IF statement in for loop

I have a loop below that I'm trying to use an IF statement only take negative tweets into my Dataframe. However, I get the following errors:

Error: unexpected '}' in "        }"
>     }
Error: unexpected '}' in "    }"

This is my code:

for (i in 1:length(WlamartTweets)) {
    #Compute polarity
    polarity=sentiment(WlamartTweets[[i]]$text)$polarity 
    #Compute created date
    created = toString(WlamartTweets[[i]]$created)
    #Compute user name
    username = WlamartTweets[[i]]$screenName
    #compute location
    location = toString(WlamartTweets[[i]]$location)
    #Compute retweet count
    retweetcount = WlamartTweets[[i]]$retweetCount
    #Compute is retweet or not
    isRetweet = WlamartTweets[[i]]$isRetweet
    #Store tweet and polarity in DF 
    sentiments = if( polarity = "negative" ) {
        rbind(sentiments, list(Tweet=WlamartTweets[[i]]$text, polarity = polarity, created = created, location =location, 
                                        username = username, retweetcount = retweetcount, isRetweet = isRetweet), stringsAsFactors=FALSE)
        }
    }

Could anyone tell me what's wrong with the syntax here?

Aucun commentaire:

Enregistrer un commentaire