I have a nested for loop in the below code.
This loops over every column and every row - is there a simple way to vectorise this?
FYI - the content of the loop verifies if the list in each entry contains only NA and thus the entire column can be removed.
# install.packages("rtweet")
library("rtweet")
rbloggers <- get_timeline(user = "Rbloggers", n = 10000)
View(rbloggers)
# install.packages("janitor")
library("janitor")
rbloggers <- janitor::remove_empty(rbloggers, which = "cols")
# this removes the columns with NA or blank - which are not in lists.
# readr::write_csv - would like to use this later and this cannot handle vector of type list.
rbloggers <- as.data.frame(rbloggers)
for (j in 1:ncol(rbloggers)){
x <- 0
for (i in 1:nrow(rbloggers)){
x <- x + all(is.na(rbloggers[i,j][[1]]))
}
# if every element is NA, then remove the column
if(x == nrow(rbloggers)) {rbloggers[,j] <- NULL}
# Many ways to remove a column:
# # Data[2] <- NULL
# # Data[[2]] <- NULL
# # Data <- Data[,-2]
# # Data <- Data[-2]
}
FYI - I am trying to understand the following references: