I have a typical problem. I have a dataset from which I have filtered the dataframe based on selected values in a column. When I check the levels it gives the same levels as before though the data frame does not show that. Please the images. The levels(gd2$Series) returns same levels as as levels(gd1$Series), why? The code is as follows
gd <- read.csv("d3.csv")
names(gd) = sub("X","",names(gd))
levels(gd$Series)
names(gd)
sapply(gd, class)
gd1 <- gd[order(gd$Series),]
rownames(gd1) <- NULL #reordering the rows
gd1[ gd1 == ".." ] <- NA
rownames(gd1) <- NULL #reordering the rows
levels(gd1$Series) # COMPARE THE LEVELS HERE WITH gd2$Series.
library(dplyr)
selected <- c("Air transport, freight (million ton-km)",
"Air transport, passengers carried",
"Railways, goods transported (million ton-km)",
"Railways, passengers carried (million passenger-km)",
"Rail lines (total route-km)")
gd2 <- as.data.frame(gd1[gd1$Series %in% selected,])
levels(gd2$Series)
The data is downloadable from this link: https://1drv.ms/u/s!AtnYqHF_dUb1gdFSRkzrlSanIIbMPg It is a small csv file.