Data type Conversion

r

#1

I have a column in my data which shows percentage of bounce rate but it is in character mode. How to convert the character mode into numeric mode so that i can divide it with any number


#2

as.numeric()


#3

I tried but then it is converting it in NA values


#4

please share few rows of the column which shows percentage of bounce rate, to debug


#5

Analytics All Web Site Data Location.csv (792 Bytes)

here is that file


#6

Hello Siddhant,

There are % symbol in your 'Bounce Rate" and other columns. You will have to strip out the % symbol before converting it to numeric.

Below is the code for that. Hope it helps.

library(data.table)

data = fread(‘Analytics All Web Site Data Location.csv’, stringsAsFactors=F)

str(data)

fixing the colnames
replacing space and \ by _

colnames(data) <- gsub(’\s+|\/’, ‘_’, colnames(data))

Bounce rate is read as character and contains %
need to clean % and convert to numeric.

data$Bounce_Rate <- as.numeric(gsub(’\%’,"",data$Bounce_Rate))

str(data)

you can process the other columns similarly :slight_smile:


#7

ok…Thank u so much. Can u tell me one more thing that which technique to use to make predictive imputation model. I am amateur currently


#8

well it depends … missing value imputation itself is a topic in itself … if you want to go with imputation with predictive model … you can use any tree based model (random forest for example) …


#9

ohh!! Thank u so much…