I have a very large data set with results and dates. A small subset of the data (I have many more columns with different names and rows):
result_1 date_1 result_2 date_2 result_3 date_3 result_4 date_4
1 1 12.8.2020 4 13.8.2020 2 15.8.2020 1 20.8.2020
2 3 15.8.2020 3 14.8.2020 5 17.8.2020 2 21.8.2020
I want to change some of the columns into numeric, depending on the column names. I thought of maybe possibly calling vectors with regex, as follows:
data$"result.*" <- as.numeric(data$"result\.*")
but it produces an error:
Error in `$<-.data.frame`(`*tmp*`, "result.*", value = numeric(0)) :
replacement has 0 rows, data has 2
I can also use mutate
or some sort of a loop, but I'm sure there's a more efficient way to do this especially since the data set is huge.