A user is importing a CSV file in R but what goes trouble is the class of the attributes change into factors as all the numeric column increases.How to fix that?

732    Asked by DavidWHITE in Data Science , Asked on Dec 12, 2019
Answered by David WHITE

If the dataset has a very less numeric column, we can change it manually by defining each column to numeric such as

df = read.csv2(file.choose(), header = T, stringsAsFactors=F)

df$LAI1 = as.numeric(df$LAI1)

df$LAI2 = as.numeric(df$LAI2)

df$LAI3 = as.numeric(df$LAI3)

Now when the columns increase it won’t be possible to define all the columns to numeric.In such cases, we can use readr::read_csv and col_types such as

df <- read_csv(file, col_types = list(LAI1 = col_number(),

   LAI2 = col_number(),

   LAI3 = col_number())



Your Answer

Interviews

Parent Categories