TransWikia.com

Why won't R recognize numbers 10 or above in my data frame?

Stack Overflow Asked by ankaa on November 29, 2021

I’m still fairly new to R, so maybe this is an obvious fix, but I’m having trouble with R recognizing numbers above 9; as shown below, I’m trying to order the data frame userCommentsDF and eventually remove any numComments entries of 10 or higher. When I order the data frame, everything is in order as it should be, except for entries of ten or higher, which appear together seemingly randomly in the middle of the dataset (between entries of 1 and 2). In addition, when I check using summary(), R tells me that there aren’t any observations within that column above 9.

Here is the code I’m currently working on:

positions <- order(userCommentDF$numComments, decreasing = T)
orderedUserComments <- userCommentDF[positions, ]
summary(userCommentDF$numComments > 9)

Here is the code I used to create the data frame:

userCommentDF <- data.frame("test", "data", "age", "gender", "location", stringsAsFactors = FALSE)
names(userCommentDF) <- c("user", "numComments", "age", "gender", "location")
userNumber <- 1
for (user in commenters){
        userCount <- (count(comments, comAuthor == user)[2, 2])
        aDF <- data.frame(user, userCount, comAge[userNumber], comGender[userNumber], comAuthorLocation[userNumber])
        names(aDF) <- c("user", "numComments", "age", "gender", "location")
        userCommentDF <- rbind(userCommentDF, aDF)
        userNumber <- userNumber + 1
}
userCommentDF <- userCommentDF[-c(1), ]

Does anyone know why this might be happening or how I might fix it?

Thank you!

EDIT: I used as.numeric() which worked.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP