Home > Software design >  Binary data column not showing correct format/values in R
Binary data column not showing correct format/values in R

Time:10-17

Im working on a project where I'm using airline data. I have retrieved the datafrom Kaggle, link to the dataset: https://www.kaggle.com/datasets/teejmahal20/aurline-passenger-satisfaction. I'm interested in the satisfaction variable which is a binary variable. Now my problem is that R is not showing the proper summary of this column. Example:

summary (airline $ Satisfaction)

Gives the output:

Length = 103904
Class: character
Mode: character

Now when i use this:

str(airline)

I get all the data about each column. Here teh satisfaction column gives:

(1)
    $ satisfaction :chr "neutral or dissatisfied", "satisfied", "neutral or dissatisfied"...

I think the correct format of this column should be:

(2)
    $ satisfaction :Factor w/ 2 levels  "neutral or dissatisfied", "satisfied": 2 1 2 2...

Now my question is, how do i transform the binary data column from (1) to (2)? Thank you for your time.

CodePudding user response:

airline$Satisfaction <- as.factor(airline$Satisfaction) 

solved it.

CodePudding user response:

Besides the answer of Larimar, you may consider using the argument stringsAsFactors=TRUE or similar when importing the dataset for example with read.csv()

  •  Tags:  
  • r
  • Related