I have a list of categories and I can get the number of apps for each category in this list. I'd like to find the 10 categories that have the most apps. I wrote this code which does not work right now, I'm getting this error:
Error in if (for (topCategoryNb in top10Nb) { :
argument is of length zero
So I'm assuming this is because a for loop cannot be put as an argument in an if statement. Is there a better way to do what I'm trying to do? If not how can I fix my code?
Here is the code:
allCategories <- list("MEDICAL", "MAPS_AND_NAVIGATION", "NEWS_AND_MAGAZINES", "VIDEO_PLAYERS", "VIDEO_PLAYERS",
"SOCIAL", "SHOPPING", "PHOTOGRAPHY", "SPORTS", "TRAVEL_AND_LOCAL", "TOOLS", "PERSONALIZATION",
"HEALTH_AND_FITNESS", "HOUSE_AND_HOME", "EVENTS")
top10 <- list()
top10Nb <- list()
for(category in allCategories){
currentNb<- numberAppPerCategories(category,0)
print(category)
print(currentNb)
if(
for(topCategoryNb in top10Nb){topCategoryNb<currentNb}
){
top10 <- c(top10, category)
}
allCategories[- category]
}
The function numberAppPerCategories return the number of apps a category has. For example, for the category "MEDICAL" we will get: (we have 0 as a second argument because that's the starting point of counting in the loop that's in the function but you can just ignore that)
> numberAppPerCategories("MEDICAL",0)
[1] 277