我有一个典型的问题。我有一个数据集,已根据一列中的选定值从中过滤出数据框。当我检查级别时,尽管数据框未显示该级别,但它提供的级别与以前相同。请图像。 级别(gd2 $ Series)返回与级别(gd1 $ Series)相同的级别,为什么? 代码如下
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)
可从以下链接下载数据:https://1drv.ms/u/s!AtnYqHF_dUb1gdFSRkzrlSanIIbMPg 这是一个小的csv文件。