首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从数据集中移除定性要素

从数据集中移除定性要素
EN

Stack Overflow用户
提问于 2020-04-28 03:40:17
回答 1查看 80关注 0票数 0

我有一个由定量和定性特征组成的数据集。如何从R中的这个数据集中删除定性特征(例如:"Auto“dataset)?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-28 05:58:03

下面标识每列的类型,然后从数据帧中删除任何不需要的数据类型

代码语言:javascript
复制
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使用的所有不同数据类型。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61467101

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档