Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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 (107k 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")

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...