Read in an variable as numeric

Hello, I just started my first RProject but sadly my data is read in wrong. Every variable value or number which contains an "," is quoted by R as "1,78". When I try to use a function for numeric numbers the program tells me, that it's not numeric. In the list of variables the variable $ Height is than listed as "1,72" "2,01" "1,80"

(Thats my data https://www.kaggle.com/datasets/haileewood/people-of-germany-east-west-division


people <- read.csv(file="data_people.csv", sep = ";", header = TRUE)

What is my mistake with the read.csv() function?

The read.csv() function also has the argument dec the sets the character used as the decimal separator. By default it is ".". You can either use

people <- read.csv(file="data_people.csv", sep = ";",  dec = ",")

or you can use

people <- read.csv2(file="data_people.csv")

The read.csv2() function has the defaults of dec = "," and sep = ";", settings commonly used in locales where the commas is the decimal separator, I believe. Note I dropped header = TRUE because that is the default in both cases. It does not do any harm to include it if you want to.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.