R: How to calculate a variable, which is stored as character?
I want to get a solution as a vector of numeric values. However, when reading my df from a csv, all the elements of the df, which contain a mix of characters and numbers (those characters are to be substituted with certain values when needed) are converted to characters. Any idea how to avoid/solve that?
This code below just simulates my problem:
#create two vectors and bind them into a df
c1 <- c("v-3", "v")
c2 <- c("1-v",0)
df <- data.frame(c1,c2)
df
c1 c2
1 v-3 1-v
2 v 0
#I would like to substitute "v" with a number
v <- 2
df
c1 c2
1 v-3 1-v
2 v 0
Now, how can I revert the class of the the elements of the df, so that the "v" can be substituted, and the values calculated? Or maybe I can read csv in such a way that my mix of characters and numbers would be stored in a more friendly way?
Thanks in advance. Greg