I have a "test" dataframe with 3 companies (ciknum variable) and years in which each company filed annual reports (fileyear):
ciknum fileyear
1 1408356 2013
2 1557255 2013
3 1557255 2014
4 1557255 2015
5 1557255 2016
6 1557255 2017
7 1555538 2014
8 1555538 2015
9 1555538 2016
10 1555538 2017
These two columns are numeric:
> is.numeric(test$ciknum)
[1] TRUE
> is.numeric(test$fileyear)
[1] TRUE
However, I need a loop that goes for each ciknum-fileyear pair to download annual reports from one site. This loop requires numeric variables for successful download, and it seems I don't get them. For instance, writing the following loop (either for the variable firm, or year, gives me that none are numeric variables):
for (row in 1:nrow(test)){
firm <- test[row, "ciknum"]
year <- test[row, "fileyear"]
my_getFilings(firm, '10-K', year, downl.permit="y") #download function over firm-year
}
Error: Input year(s) is not numeric #error repeated 10 times (one per row)
I checked whether new df firm and year are numeric, and there is mixed evidence. On the one hand, it seems it reads year as numeric variable:
> for (row in 1:nrow(test)){
+ firm <- test[row, "ciknum"]
+ year <- test[row, "fileyear"]
+
+ if(year>2015) {
+ print(paste("I have this", firm, "showing a numeric", year))
+ }
+ }
[1] "I have this 1557255 showing a numeric 2016" #it only states years>2015. Seems it reads a number
[1] "I have this 1557255 showing a numeric 2017"
[1] "I have this 1555538 showing a numeric 2016"
[1] "I have this 1555538 showing a numeric 2017"
But on the other hand, it seems it does not:
> for (row in 1:nrow(test)){
+ firm <- test[row, "ciknum"]
+ year <- test[row, "fileyear"]
+
+ if(!is.numeric(year)) {
+ print(paste("is not numeric"))
+ }
+ }
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
[1] "is not numeric"
Can anyone tell me whether these are numeric variables or not? Getting lost on this one... My download function "my_getFilings" seems to depend on that. Thank you in advance.