반응형 summarise()3 (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) ifelse() ifelse() Using ifelse(), you can make a new variable based on the test you made. >library(ggplot2)> summary(diamonds$carat) -------------carat: size of carat in each diamond Min. 1st Qu. Median Mean 3rd Qu. Max. 0.2000 0.4000 0.7000 0.7979 1.0400 5.0100 To make a new variable 'carattt' which consists of small and big, I will use a test in ifelse() 1st test:diamonds$carat diamonds$carattt carattt.. 2020. 7. 23. (R) make a summary - group_by(),summarise() >library(ggplot2) ------------------for mpg>library(dplyr) ------------------for summarise() >mpg%>%summarise(mean_cty=mean(cty)) # A tibble: 1 x 1mean_cty 1 16.9 A summary of a group(drv) by mean_cty >drv_cty%group_by(drv)%>%summarise(mean_cty=mean(cty)) > drv_cty # A tibble: 3 x 2 drv mean_cty 1 4 14.32 f 20.03 r 14.1 A summary of groups of drv, manufacturer (4,f,r - Audi,Chevrolet, ...) by me.. 2020. 7. 22. 이전 1 다음 반응형