Hi All- I am running a sentiment scoring model and the code is as below: sentiments_per_Category <- aggregate(relative_sentiment_frequencies, by = list(Category df$Case.Category), mean) while i run the head command most of the values are NaN. i then used complete.cases on my data frame df[complete.cases(df),] but it does not seems to work. Please advice if there is a way to handle NaN. Regards, Shivi [[alternative HTML version deleted]]
Did you keep the resulting complete cases version of df? dfc <- df[complete.cases(df),] and then use that as input? On August 25, 2018 7:00:47 AM PDT, Shivi Bhatia <shivipmp82 at gmail.com> wrote:>Hi All- I am running a sentiment scoring model and the code is as >below: >sentiments_per_Category <- aggregate(relative_sentiment_frequencies, > by = list(Category >df$Case.Category), mean) > >while i run the head command most of the values are NaN. i then used >complete.cases on my data frame >df[complete.cases(df),] >but it does not seems to work. Please advice if there is a way to >handle >NaN. > >Regards, Shivi > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- Sent from my phone. Please excuse my brevity.
Hi the output seems to me rather weird. Unles you have NaNs in input data frame you should not get NaN as a result. Anyway, your aggregate will give you NA or NaN even when there is only one NA or NaN in your input data frame. So I suggest to use sentiments_per_Category <- aggregate(relative_sentiment_frequencies, by = list(Category = df$Case.Category), mean, na.rm=TRUE) This should strip all NAs before calculating mean in each category. Complete cases removes all lines with at least one NA in your data frame, which probably results to empty data frame. Cheers Petr> -----Original Message----- > From: R-help <r-help-bounces at r-project.org> On Behalf Of Shivi Bhatia > Sent: Saturday, August 25, 2018 4:01 PM > To: R-help <r-help at r-project.org> > Subject: [R] NaN in Scoring Sentiment > > Hi All- I am running a sentiment scoring model and the code is as below: > sentiments_per_Category <- aggregate(relative_sentiment_frequencies, > by = list(Category = df$Case.Category), mean) > > while i run the head command most of the values are NaN. i then used > complete.cases on my data frame df[complete.cases(df),] but it does not seems > to work. Please advice if there is a way to handle NaN. > > Regards, Shivi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner?s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/ D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
Thanks you Petr. This worked.? Regards, Shivi? Sent from Yahoo Mail for iPhone On Monday, August 27, 2018, 14:31, PIKAL Petr <petr.pikal at precheza.cz> wrote: Hi the output seems to me rather weird. Unles you have NaNs in input data frame you should not get NaN as a result. Anyway, your aggregate will give you NA or NaN even when there is only one NA or NaN in your input data frame. So I suggest to use sentiments_per_Category <- aggregate(relative_sentiment_frequencies,? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? by = list(Category = df$Case.Category), mean, na.rm=TRUE) This should strip all NAs before calculating mean in each category. Complete cases removes all lines with at least one NA in your data frame, which probably results to empty data frame. Cheers Petr> -----Original Message----- > From: R-help <r-help-bounces at r-project.org> On Behalf Of Shivi Bhatia > Sent: Saturday, August 25, 2018 4:01 PM > To: R-help <r-help at r-project.org> > Subject: [R] NaN in Scoring Sentiment > > Hi All- I am running a sentiment scoring model and the code is as below: > sentiments_per_Category <- aggregate(relative_sentiment_frequencies, >? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? by = list(Category = df$Case.Category), mean) > > while i run the head command most of the values are NaN. i then used > complete.cases on my data frame df[complete.cases(df),]? but it does not seems > to work. Please advice if there is a way to handle NaN. > > Regards, Shivi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner?s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/ D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ [[alternative HTML version deleted]]