Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (50.2k points)

I am having a data frame -"reviews" and from that, I want to eliminate a specific row that comprises of the character "NaN" in the column SentimentGI.

I tried to use the code below but it didn't work. 

Sentiment_analyze <- analyzeSentiment(reviews$Review)

reviews$sentiment <-Sentiment_analyze$SentimentGI

for(i in reviews$SentimentGI) {

  if(i == "NaN") {

    reviews <- reviews[-i]

    }

}

1 Answer

0 votes
by (108k points)

In R programming you can use the subset with !is.na() if your NaN is a Not Available value

newdf <- subset(reviews, !is.na(SentimentGI))

But if your NaN is a character, then you just have to perform the following subsetting:

newdf <- subset(reviews, SentimentGI != "NaN")

Browse Categories

...