
데이터 생성 > # 중간고사 데이터 생성 > test1 > # 기말고사 데이터 생성 > test2 test1 id midterm 1 1 60 2 2 80 3 3 70 4 4 90 5 5 85 > test2 id final 1 1 70 2 2 83 3 3 65 4 4 95 5 5 80 left_join() * by에 변수명을 지정할 때 변수명 앞 뒤에 겹따옴표 입력 > total total id midterm final 1 1 60 70 2 2 80 83 3 3 70 65 4 4 90 95 5 5 85 80 > name name class teacher 1 1 kim 2 2 lee 3 3 park 4 4 choi 5 5 jung > exam_new exam_new id class math english s..
> mpg %>% + filter(class == "compact") %>% # compact 추출 + group_by(manufacturer) %>% # manufacturer별 분리 + summarise(count = n()) %>% # 빈도 구하기 + arrange(desc(count)) # 내림차순 정렬 # A tibble: 5 × 2 manufacturer count 1 audi 15 2 volkswagen 14 3 toyota 12 4 subaru 4 5 nissan 2 Q1. 어떤 회사에서 "compact"(경차) 차종을 가장 많이 생산하는지 알아보려고 합니다. 각 회사별 "compact" 차종 수를 내림차순으로 정렬해 출력하세요. > mpg %>% + group_by(manufacturer..
집단별로 요약하기 > exam %>% + summarise(mean_math=mean(math)) mean_math 1 57.45 > exam %>% + group_by(class) %>% + summarise(mean_math=mean(math)) # A tibble: 5 × 2 class mean_math 1 1 46.2 2 2 61.2 3 3 45 4 4 56.8 5 5 78 > exam %>% + group_by(class) %>% + summarise(mean_math=mean(math), + sum_math=sum(math), + median_math=median(math), + n=n()) # A tibble: 5 × 5 class mean_math sum_math median_math n ..

파생변수 추가하기 (열 추가) > exam %>% + mutate(total=math+english+science) %>% + head id class math english science total 1 1 1 50 98 50 198 2 2 1 60 97 60 217 3 3 1 45 86 78 209 4 4 1 30 98 58 186 5 5 2 25 80 65 170 6 6 2 50 89 98 237 > exam %>% + mutate(total = math + english + science, + mean = (math + english + science)/3) %>% + head() id class math english science total mean 1 1 1 50 98 50 198 66.000..

더보기 순서대로 정렬하기 #기본 오름차순 > exam %>% arrange(math) id class math english science 1 9 3 20 98 15 2 5 2 25 80 65 3 4 1 30 98 58 4 3 1 45 86 78 5 12 3 45 85 32 6 13 4 46 98 65 7 14 4 48 87 12 8 1 1 50 98 50 9 6 2 50 89 98 10 10 3 50 98 45 11 16 4 58 98 65 12 2 1 60 97 60 13 11 3 65 65 65 14 17 5 65 68 98 15 15 4 75 56 78 16 20 5 78 83 58 17 7 2 80 90 45 18 18 5 80 78 90 19 19 5 89 68 87 20 8 2 90 78 2..

select()를 이용하여 변수 이름으로 열 선택하기 select() 함수는 다음처럼 변수 이름을 일일이 나열하여 원하는 열을 선택할 수 있다. R의 기본 문법을 알고 있는 사람들은 데이터 프레임의 인덱싱에서처럼 문자열로 이름을 나열하는 것이 아니라 변수를 사용하듯 따옴표 없이 이름을 나열하는 것에 주의한다. select(데이터프레임, 변수이름1, 변수이름 2, ....) > exam %>% select(math) math 1 50 2 60 3 45 4 30 5 25 6 50 7 80 8 90 9 20 10 50 > exam %>% select(math) math 1 50 2 60 3 45 4 30 5 25 6 50 7 80 8 90 9 20 10 50 > exam %>% select(class, mat..
함수 기능 filter() 행 추출 select() 열(변수) 추출 arrange() 정렬 mutate() 변수 추가 summarise() 통계치 산출 group_by() 집단별로 나누기 left_join() 데이터 합치기(열) bind_rows() 데이터 합치기(행) 1.데이터 준비 > exam exam id class math english science 1 1 1 50 98 50 2 2 1 60 97 60 3 3 1 45 86 78 4 4 1 30 98 58 5 5 2 25 80 65 6 6 2 50 89 98 7 7 2 80 90 45 8 8 2 90 78 25 9 9 3 20 98 15 10 10 3 50 98 45 11 11 3 65 65 65 12 12 3 45 85 32 13 13 4 46..
numeric - (10.5, 55, 787) integer - (1L, 55L, 100L, where the letter "L" declares this as an integer) complex - (9 + 3i, where "i" is the imaginary part) character (a.k.a. string) - ("k", "R is exciting", "FALSE", "11.5") logical (a.k.a. boolean) - (TRUE or FALSE) type 확인 : class() > # numeric > x class(x) [1] "numeric" > > # integer > x class(x) [1] "integer" > > # complex > x class(x) [1] "com..
시작 Project 시작 Script 시작 : ctrl + shift + N 작업 경로 설정 : ctrl + shift + H > setwd("C:/Users/USER/Desktop/mystudy/dataR") a a [1] 1 2 3 4 5 6 7 8 9 10 ls()를 사용해서 프로그램에 사용된 변수를 출력한다. rm()을 사용해서 프로그램에 사용된 객체를 삭제한다. > ls() [1] "a" > rm(a) > a Error: object 'a' not found install.packages()을 사용해서 팩키지(라이브러리)를 설치한다. 메뉴 > [tools] > install.package install.packages("dplyr") library(dplyr) R 도움말 : ?함수명() or h..
- Total
- Today
- Yesterday