I working with a data set that contains numbers stored as characters. Below you can see data example of data extracted with the dput function:
structure(list(Y_O_13_Males = c("10", "0", "0", "0", "0", "0",
"0", "0", "0", "0"), Y_O_13_Females = c("1", "0", "0", "0", "0",
"0", "0", "0", "0", "0"), Y_O_13_Unknown = c("7", "0", "0", "0",
"0", "0", "0", "0", "0", "0"), Y14_17_Males = c("2", "0", "0",
"0", "0", "0", "0", "0", "0", "0"), Y14_17_Females = c("0", "0",
"0", "0", "0", "0", "0", "0", "0", "0"), Y14_17_Unknown = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y18_34_Males = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y18_34_Females = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y18_34_Unknown = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y35_64_Males = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y35_64_Females = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y35_64_Unknown = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y65_And_Over_Males = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y65_And_Over_Females = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y65_And_Over_Unknown = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Unknown_And_Over_Males = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Unknown_And_Over_Females = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Unknown_And_Over_Unknown = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0")), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
Now I want to convert all of this data from character format to numeric.I tryed with this line of code but is not working.
df[,1:18]<-as.numeric(df[,1:18])
So can anybody help me how to solve this problem?