R語言 資料預處理

2021-07-28 02:49:28 字數 884 閱讀 9904

資料預處理的常見做法

寫完**,閒來無事,想寫寫部落格!

這是我寫的第一篇文章,請多多支援!謝謝!

data<-read.csv("data.csv")#讀入資料

dim(data)#看資料中有多少行,多少列

str(data)#看資料中變數型別

summary(iris)#數值型的變數給出最大,最小,中位數,均值,上下四分位數;分型別的給出變數型別以及個數

**通過上面三個函式基本可以了解資料集中變數的個數以及型別**

data$label

<-factor(data$label)#把label變數轉變為因子型

which(complete.cases(data) == f)#看哪行有缺失值

data_new<-data[!is.na(data$age),]#去掉age變數中的缺失值

data_new<-data_new[order(salary,decreasing=f),]#salary變數公升序排列

把資料中的所有因子型變數轉換成啞變數

篩選出資料中的所有因子型變數

把這些因子型變數貼上到formula的右邊

轉換為啞變數

**如下:

facots

formula

<-as.formula(paste('~',paste(facots,collapse = '+')))

dummy

<-dummyvars(formula = formula, data = data)

pred

<-predict(dummy, newdata = data)

head(pred)

一 R 語言 資料預處理 方法和步驟

一 分析單變數常用的函式 用r 自帶的資料bjsales 基本資料檢視 均值view bjsales mean bjsales mean bjsales,trim 0.1 中位數 median bjsales 分位數 quantile bjsales quantile bjsales,c 0.1,0...

R語言 實驗三 資料探索和預處理

計算缺失值個數 計算缺失率 簡單統計量 計算最值 箱形圖分析 分布分析 畫出頻率直方圖 統計量分析 對於連續屬性值,求出均值以及標準差 缺失值處理 刪除法 去除無用屬性 刪除 id 屬性 或者 離散化 把 children 屬性轉換成分型別的兩個值 yes 和 no 把income屬性按照節點126...

R語言 資料處理 R語言資料變形melt用法

1 需要安裝的包 install.packages reshape2 install.packages knitr 2 載入包 rm list ls gc library reshape2 library knitr 3 建立資料集 data data4 變形之前資料展示 kable data,fo...