我有一个由定量和定性特征组成的数据集。如何从R中的这个数据集中删除定性特征(例如:"Auto“dataset)?
发布于 2020-04-28 05:58:03
下面标识每列的类型,然后从数据帧中删除任何不需要的数据类型
library(ISLR)
data <- Auto
# Get Data Types of all Columns in the Data Frame
column_types <- sapply(data, class)
# Create a vector to hold all the unwanted data types (Change to what you want)
unwanted_types <- c("factor", "character")
# Remove all the columns which are of the unwanted datatypes
data <- data[, which(!column_types %in% unwanted_types)]
# Get Summary of the DataFrame
summary(data)
mpg cylinders displacement horsepower weight acceleration year origin
Min. : 9.00 Min. :3.000 Min. : 68.0 Min. : 46.0 Min. :1613 Min. : 8.00 Min. :70.00 Min. :1.000
1st Qu.:17.00 1st Qu.:4.000 1st Qu.:105.0 1st Qu.: 75.0 1st Qu.:2225 1st Qu.:13.78 1st Qu.:73.00 1st Qu.:1.000
Median :22.75 Median :4.000 Median :151.0 Median : 93.5 Median :2804 Median :15.50 Median :76.00 Median :1.000
Mean :23.45 Mean :5.472 Mean :194.4 Mean :104.5 Mean :2978 Mean :15.54 Mean :75.98 Mean :1.577
3rd Qu.:29.00 3rd Qu.:8.000 3rd Qu.:275.8 3rd Qu.:126.0 3rd Qu.:3615 3rd Qu.:17.02 3rd Qu.:79.00 3rd Qu.:2.000
Max. :46.60 Max. :8.000 Max. :455.0 Max. :230.0 Max. :5140 Max. :24.80 Max. :82.00 Max. :3.000 我还建议阅读R使用的所有不同数据类型。
https://stackoverflow.com/questions/61467101
复制相似问题