I am working on a video game dataset and would like a variable column that counts the number of games produced for each platform. I ordered it by year, so ideally it will be a cumulative total over-time for each platform. Here is the function that I tried, but did not work.
counting <- function(w) {
i = 0
j = 0
k = 0
l = 0
m = 0
for (val in w) {
if(val == "PC"){
i = i+1
i
} else if (val == "Xbox"){
j = j+1
j
}else if (val == "Nintendo"){
k = k+1
k
} else if (val == "Playstation"){
l = l+1
l
} else if (val == "Others"){
m = m+1
m
}
}
}
my_vector2 <- sapply(data$Platform.type, counting)
Does anyone have any suggestions? All I am getting is a really long vector of null.
Aucun commentaire:
Enregistrer un commentaire