so this is my code so far. My extractDate works and gives me "##" formats. However, I'm having a big of trouble with getYears function- my intention is given in the code comments below. Basically, I want to attach either 19 or 20 or 200 to numbers based on the value it has. I keep getting this error:
Error in if (as.numeric(spotify$rel_date[i]) > 22) { :
missing value where TRUE/FALSE needed
Can anyone please help me out or provide an alternative solution to my problem? Thank you!!!
The spotify release dates are either formatted as dd-mmm-yy / mmm-yy / yyyy
## To standardize the years, extract the last two numbers and add 19 or 20 to prefix
##' extractDate function
##' @string is the Date in string format to extract the year from
##' @n is the number of characters to extract from the string
##' substr(x, start, stop) from RDocumentation
extractDate = function(string, n){
extract =substr(string, nchar(string)-n+1, nchar(string))
}
##' getYears function
##' @string is the Date in string format to add onto to make a proper year
##' For any numbers "##" greater than 22, we will attach "19" in the prefix (i.e.: "1967")
##' For any numbers "##" less or equal to 22, we will attach "20" in the prefix (i.e: "2006")
getYears = function(string){
if (as.numeric(string)>22){
string=paste0("19",string)
}
else {
string=paste0("20",string)
}
}
## spoti$rel_date=extractDate(spoti$rel_date,2)
spotify$rel_date=extractDate(spotify$rel_date,2)
spotify$rel_date
for (i in spotify$rel_date){
if (as.numeric(spotify$rel_date[i])>22){
spotify$rel_date[i]=paste0("19",spotify$rel_date[i])
}
else if (as.numeric(spotify$rel_date[i]<10)){
spotify$rel_date[i]=paste0("200",spotify$rel_date[i])
}
else {
spotify$rel_date[i]=paste0("20",spotify$rel_date[i])
}
}