I have a data frame 'qlfs' which contains a column 'qlfs$TravelMode'.
The $TravelMode is a factor containing 10 levels:
levels(qlfs$TravelMode)
[1] "Non-working adult"
[2] "Car,van,minibus,works van"
[3] "Motorbike,moped,scooter"
[4] "Bicycle"
[5] "Bus,coach,private bus"
[6] "Taxi"
[7] "Railway train"
[8] "Underground train,light railway,tram"
[9] "Walk"
[10] "Other method"
The dataset contains 90k + rows.
I would like to remove level 1 (Non-working adult) and any associated rows from the wider dataframe.
I have tried the following:
for (i in 1:NROW(qlfs$TravelMode)) {
if(qlfs$TravelMode[i]="Non-working adult") {
qlfs$TravelMode[i] <- "NA"
}
}
Where I would then remove the NAs at a later point, but this did not work.
I have also looked at droplevels() function, but could not get this to work.
Can anybody point out where I am going wrong or suggest a better way to achieve this?