R tips 데이터 정리에 사용할 수 있는 라이브러리 dplyr
10905 단어 R
기사의 목적
데이터를 정리할 때 매우 사용할 수 있는 라이브러리인 'dplyr'에 대해 몇 가지 설명합니다!
여기에 실어있는 소스 코드는 copipe로 전부 재현할 수 있습니다.
목차
No.
목차
설명
1
라이브러리 및 사용할 데이터
dplyr/iris
2
sample_n
데이터에서 임의로 일부 추출
3
선택
조건에 맞는 "열"추출
4
filter
조건에 맞는 "행"추출
5
group_by+summarise
그룹별 통계량 등 추출
6
mutate
데이터를 긁어 새 열 추가
7
arrange
정렬 (오름차순, 내림차순)
8
rename
열 이름 바꾸기
1. 라이브러리와 사용할 데이터
library는 물론 dplyr입니다!
데이터는 iris의 데이터 세트를 사용합니다.
library(dplyr)
iris %>% head()

2. sample_n (데이터에서 임의로 일부 추출)
iris %>% sample_n(5)

3. select (조건에 맞는 "열"추출)
iris %>% select(Sepal.Length) %>% sample_n(5)

4. filter (조건에 맞는 "행"추출)
#種類を確認 (uniqueはdplyr関係ないです。)
iris$Species %>% unique()

#種類で指定
iris %>% filter(Species=="versicolor") %>% sample_n(5)

#数値で指定
iris %>% filter(Sepal.Length>6.5) %>% sample_n(5)

5. group_by+summarise (그룹별 통계량 등 추출)
iris %>% group_by(Species) %>%
summarise(Sepal縦の長さの平均=mean(Sepal.Length),
Sepal横の長さの合計=sum(Sepal.Width))

6. mutate (데이터를 괴롭히고 새 열 추가)
#足し算の列を追加
iris %>% mutate(Sepal縦と横の合計=Sepal.Length+Sepal.Width) %>%
sample_n(5)

#クラスを数字に変換
#ifelse(条件,条件がTRUEのときの値,条件がFALSEのときの値)
iris %>% mutate(class=ifelse(Species=="setosa",1,
ifelse(Species=="versicolor",2,3))) %>%
sample_n(5)

7. arrange (정렬)
#昇順
iris %>% arrange(Sepal.Length) %>% head(5)

#降順
iris %>% arrange(desc(Sepal.Length)) %>% head(5)

8. rename (컬럼 이름 바꾸기)
iris %>% rename(種類=Species) %>% sample_n(5)
Reference
이 문제에 관하여(R tips 데이터 정리에 사용할 수 있는 라이브러리 dplyr), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Tatsuki-Oike/items/c0a2ef2be464d06c831c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
No.
목차
설명
1
라이브러리 및 사용할 데이터
dplyr/iris
2
sample_n
데이터에서 임의로 일부 추출
3
선택
조건에 맞는 "열"추출
4
filter
조건에 맞는 "행"추출
5
group_by+summarise
그룹별 통계량 등 추출
6
mutate
데이터를 긁어 새 열 추가
7
arrange
정렬 (오름차순, 내림차순)
8
rename
열 이름 바꾸기
1. 라이브러리와 사용할 데이터
library는 물론 dplyr입니다!
데이터는 iris의 데이터 세트를 사용합니다.
library(dplyr)
iris %>% head()

2. sample_n (데이터에서 임의로 일부 추출)
iris %>% sample_n(5)

3. select (조건에 맞는 "열"추출)
iris %>% select(Sepal.Length) %>% sample_n(5)

4. filter (조건에 맞는 "행"추출)
#種類を確認 (uniqueはdplyr関係ないです。)
iris$Species %>% unique()

#種類で指定
iris %>% filter(Species=="versicolor") %>% sample_n(5)

#数値で指定
iris %>% filter(Sepal.Length>6.5) %>% sample_n(5)

5. group_by+summarise (그룹별 통계량 등 추출)
iris %>% group_by(Species) %>%
summarise(Sepal縦の長さの平均=mean(Sepal.Length),
Sepal横の長さの合計=sum(Sepal.Width))

6. mutate (데이터를 괴롭히고 새 열 추가)
#足し算の列を追加
iris %>% mutate(Sepal縦と横の合計=Sepal.Length+Sepal.Width) %>%
sample_n(5)

#クラスを数字に変換
#ifelse(条件,条件がTRUEのときの値,条件がFALSEのときの値)
iris %>% mutate(class=ifelse(Species=="setosa",1,
ifelse(Species=="versicolor",2,3))) %>%
sample_n(5)

7. arrange (정렬)
#昇順
iris %>% arrange(Sepal.Length) %>% head(5)

#降順
iris %>% arrange(desc(Sepal.Length)) %>% head(5)

8. rename (컬럼 이름 바꾸기)
iris %>% rename(種類=Species) %>% sample_n(5)
Reference
이 문제에 관하여(R tips 데이터 정리에 사용할 수 있는 라이브러리 dplyr), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Tatsuki-Oike/items/c0a2ef2be464d06c831c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
library(dplyr)
iris %>% head()
iris %>% sample_n(5)

3. select (조건에 맞는 "열"추출)
iris %>% select(Sepal.Length) %>% sample_n(5)

4. filter (조건에 맞는 "행"추출)
#種類を確認 (uniqueはdplyr関係ないです。)
iris$Species %>% unique()

#種類で指定
iris %>% filter(Species=="versicolor") %>% sample_n(5)

#数値で指定
iris %>% filter(Sepal.Length>6.5) %>% sample_n(5)

5. group_by+summarise (그룹별 통계량 등 추출)
iris %>% group_by(Species) %>%
summarise(Sepal縦の長さの平均=mean(Sepal.Length),
Sepal横の長さの合計=sum(Sepal.Width))

6. mutate (데이터를 괴롭히고 새 열 추가)
#足し算の列を追加
iris %>% mutate(Sepal縦と横の合計=Sepal.Length+Sepal.Width) %>%
sample_n(5)

#クラスを数字に変換
#ifelse(条件,条件がTRUEのときの値,条件がFALSEのときの値)
iris %>% mutate(class=ifelse(Species=="setosa",1,
ifelse(Species=="versicolor",2,3))) %>%
sample_n(5)

7. arrange (정렬)
#昇順
iris %>% arrange(Sepal.Length) %>% head(5)

#降順
iris %>% arrange(desc(Sepal.Length)) %>% head(5)

8. rename (컬럼 이름 바꾸기)
iris %>% rename(種類=Species) %>% sample_n(5)
Reference
이 문제에 관하여(R tips 데이터 정리에 사용할 수 있는 라이브러리 dplyr), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Tatsuki-Oike/items/c0a2ef2be464d06c831c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
iris %>% select(Sepal.Length) %>% sample_n(5)
#種類を確認 (uniqueはdplyr関係ないです。)
iris$Species %>% unique()

#種類で指定
iris %>% filter(Species=="versicolor") %>% sample_n(5)

#数値で指定
iris %>% filter(Sepal.Length>6.5) %>% sample_n(5)

5. group_by+summarise (그룹별 통계량 등 추출)
iris %>% group_by(Species) %>%
summarise(Sepal縦の長さの平均=mean(Sepal.Length),
Sepal横の長さの合計=sum(Sepal.Width))

6. mutate (데이터를 괴롭히고 새 열 추가)
#足し算の列を追加
iris %>% mutate(Sepal縦と横の合計=Sepal.Length+Sepal.Width) %>%
sample_n(5)

#クラスを数字に変換
#ifelse(条件,条件がTRUEのときの値,条件がFALSEのときの値)
iris %>% mutate(class=ifelse(Species=="setosa",1,
ifelse(Species=="versicolor",2,3))) %>%
sample_n(5)

7. arrange (정렬)
#昇順
iris %>% arrange(Sepal.Length) %>% head(5)

#降順
iris %>% arrange(desc(Sepal.Length)) %>% head(5)

8. rename (컬럼 이름 바꾸기)
iris %>% rename(種類=Species) %>% sample_n(5)
Reference
이 문제에 관하여(R tips 데이터 정리에 사용할 수 있는 라이브러리 dplyr), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Tatsuki-Oike/items/c0a2ef2be464d06c831c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
iris %>% group_by(Species) %>%
summarise(Sepal縦の長さの平均=mean(Sepal.Length),
Sepal横の長さの合計=sum(Sepal.Width))
#足し算の列を追加
iris %>% mutate(Sepal縦と横の合計=Sepal.Length+Sepal.Width) %>%
sample_n(5)

#クラスを数字に変換
#ifelse(条件,条件がTRUEのときの値,条件がFALSEのときの値)
iris %>% mutate(class=ifelse(Species=="setosa",1,
ifelse(Species=="versicolor",2,3))) %>%
sample_n(5)

7. arrange (정렬)
#昇順
iris %>% arrange(Sepal.Length) %>% head(5)

#降順
iris %>% arrange(desc(Sepal.Length)) %>% head(5)

8. rename (컬럼 이름 바꾸기)
iris %>% rename(種類=Species) %>% sample_n(5)
Reference
이 문제에 관하여(R tips 데이터 정리에 사용할 수 있는 라이브러리 dplyr), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Tatsuki-Oike/items/c0a2ef2be464d06c831c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#昇順
iris %>% arrange(Sepal.Length) %>% head(5)
#降順
iris %>% arrange(desc(Sepal.Length)) %>% head(5)
iris %>% rename(種類=Species) %>% sample_n(5)

Reference
이 문제에 관하여(R tips 데이터 정리에 사용할 수 있는 라이브러리 dplyr), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Tatsuki-Oike/items/c0a2ef2be464d06c831c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)