Currently I'm learning to use R for simple financial calculations. I have seven data frames and I'm trying to apply the same function to all of them. The vector names are the same for all dfs starting with "Date" and are initially "chars". I managed to convert every "Date" vector to the date format with:
listOf <- c(Invesco2, Lyxor1, Lyxor2, ComStage, Ossiam, SPDR, Vanguard) # list of dfs
for (i in listOf){
i[1] <- as.Date(i[1], "%d-%m-%y")
}
Now I'm trying to change the rest of vectors to numeric with again a for loop and "lapply":
lapply(listOf, as.numeric)
The console just prints all the vectors and gives 37 errors: "In lapply(listOf, as.numeric) : NAs introduced by coercion"
for (i in listOf){
i <- as.numeric(i)
}
Again 37 Errors: In as.numeric(i) : NAs introduced by coercion In both cases nothing changed. Pls help
EDIT: There is a sample a the data set:
# Create the sample vectors
Date <- c("23-01-19", "24-01-19", "25-01-19", "26-01-19", "27-01-19" )
Open <- c("69.849998", "69.440002", "69.540001", "70.32", "69.559998")
High <- c("69.849998", "69.440002", "69.540001", "70.32", "69.559998")
Low <- c("69.849998", "69.440002", "69.540001", "70.32", "69.559998")
Close <- c("69.849998", "69.440002", "69.540001", "70.32", "69.559998")
Adj_Close <- c("69.849998", "69.440002", "69.540001", "70.32", "69.559998")
Volume <- c("0", "0", "0", "0","0")
# Create df
InvescoDf <- data.frame(Date, Open, High, Low, Close, Adj_Close, Volume)
# Create another df
OssiamDf <- InvescoDf
# Put in list together
new_list <- list(InvescoDf, OssiamDf)
EDIT 2: It creates factors. In the orginal data the vectors are chars.
EDIT 3:
Date Open High Low Close `Adj Close` Volume
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 23-01-19 69.849998 69.849998 69.849998 69.849998 69.849998 0
2 24-01-19 69.440002 69.440002 69.440002 69.440002 69.440002 0
3 25-01-19 69.540001 69.540001 69.540001 69.540001 69.540001 0
4 28-01-19 70.32 70.32 70.32 70.32 70.32 0
5 29-01-19 69.559998 69.559998 69.559998 69.559998 69.559998 0
6 30-01-19 69.580002 69.580002 69.580002 69.580002 69.580002 0
BR Toni