Converting char dataframe column to int column

Hello,

I imported csv. file to the R from Kaggle.
"Income" column of my dataset is in char type inside quotation marks:

str(data)
$ Income : chr "$84,835.00 " "$57,091.00 " "$67,267.00 " "$32,474.00 "

How can I convert this column to int type? I tried some functions but I got full NA results.

In this way, I can not analyse this column in terms of mean,median,distribution etc.

Thank you.

I would use the sub() function to remove the dollar signs and commas.

DF <- data.frame(A=c("$84,235.00","$45,678.00"))
DF$A
[1] "$84,235.00" "$45,678.00"
DF$A <- sub("\\$","",DF$A)
DF$A <- sub(",","",DF$A)
DF$A <- as.integer(DF$A)
DF$A
[1] 84235 45678
1 Like
readr::parse_number()

will probably help you, as you can let it do basic interpretation to at least get you to where the variable is a number without doing your own string manipulation.

oh my gosh, this function is so basic thanks!