r – Unknown or uninitialised column
I have the below warning; due to which I am facing errors while executing the code.
Unknown or uninitialised column:
total_books
.
###books is my data frame
book_publishers <- summarise(group_by(books,publisher), total_books = n())
book_publishers
book_publishers<- drop_na(book_publishers)
book_publishers <- filter(book_publishers, total_books>250)
book_publishers
book_publishers <- arrange(book_publishers, desc(total_books))
book_publishers
book_publishers$publisher <- factor(book_publishers$publisher, levels = book_publishers$publisher)
book_publishers<- mutate(book_publishers,
cum_count = cumsum(total_books),
rel_freq = total_books / sum(total_books),
cum_freq = cumsum(rel_freq))
book_publishers
I tried comparing to compare with the expected value
if (random_house_total == 2607) {
cat("Total books for Random House match the expected value.\n")
} else {
cat("Total books for Random House do not match the expected value.\n")
cat("Expected: 2607\n")
cat("Actual:", random_house_total, "\n")
}
o/p: Total books for Random House do not match the expected value.
Expected: 2607
Actual: 0
This is beacuse, the ‘total_books’ is not initialized
Can I get some help in understanding and resolving the issue?
Read more here: Source link