반응형 R71 (R) coord_flip() coord_flip() >?coord_flip When assigning manufacturer variable of mpg to x-axis, It is hard to seize the name of elements of manufacturer variable. Because 'manufacturer' in 'mpg' tend to be overlapped having a long elements such as 'volkswagen','toyota'. So we need to flip the columns to horizontal so that elements are not overlapped. > manufacturer_class%count(manufacturer,class)%>%group_by(ma.. 2020. 7. 30. (R) count the number of elements/ count() count(): count the number of elements of each variable >?count df%>%group_by(a,b)%>%summarise(n=n() ∥∥df%>%count(a,b) > mpg2%select(manufacturer,class)%>%filter(manufacturer=="audi")> mpg2# A tibble: 18 x 2 manufacturer class 1 audi compact 2 audi compact 3 audi compact 4 audi compact 5 audi compact 6 audi compact 7 audi compact 8 audi compact 9 audi compact10 audi compact11 audi compact12 audi .. 2020. 7. 29. (R)Make a new variable/ mutate() mutate() : make a new variable 'msleep' is a data set in ggplot2 which consists of 'name', 'genus' , 'vore',...'bodywt'. I will make a new data set named 'new_msleep' which contains a new variable 'ratio_ram' which does not exist in 'msleep' data set. >library(ggplot2) -----------for dataset 'msleep' in ggplot2>library(dplyr) ------------for mutate(), filter() > str(msleep)tibble [61 x 12] (S3: .. 2020. 7. 27. (R) [dplyr] Rearrange data in order / arrange() / arrange(desc()) >library(ggplot2)>library(dplyr) > the_number_of_each_manu%group_by(manufacturer)%>%summarise(n=n()) > the_number_of_each_manu# A tibble: 15 x 2 manufacturer n 1 audi 18 2 chevrolet 19 3 dodge 37 4 ford 25 5 honda 9 6 hyundai 14 7 jeep 8 8 land rover 4 9 lincoln 310 mercury 411 nissan 1312 pontiac 513 subaru 1414 toyota 3415 volkswagen 27 arrange()-order in the smallest to the largest > the_numb.. 2020. 7. 26. 이전 1 ··· 13 14 15 16 17 18 다음 반응형