getwd() # 작업공간 확인 함수 
## [1] "C:/2023교통대 대학원"
setwd('c:/data')
df<-read.csv("Data1.csv")
library(dplyr)
## 
## 다음의 패키지를 부착합니다: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
glimpse(df)
## Rows: 1,925
## Columns: 26
## $ Q1        <int> 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, …
## $ Q2        <int> 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 2, 2, …
## $ Q3        <int> 2, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 3, 2, 3, …
## $ Q4        <int> 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 2, 4, …
## $ Q5        <int> 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 4, 3, 1, 2, …
## $ Q6        <int> 2, 3, 4, 4, 4, 4, 4, 4, 1, 2, 2, 2, 4, 4, 3, 5, 2, 2, 1, 4, …
## $ Q7        <int> 2, 2, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 5, 4, 4, 5, 4, 3, 4, 4, …
## $ Q8        <int> 4, 4, 4, 4, 4, 4, 5, 5, 2, 2, 4, 4, 4, 4, 3, 5, 4, 2, 4, 4, …
## $ Q9        <int> 4, 4, 4, 4, 2, 4, 5, 5, 3, 4, 4, 4, 2, 2, 4, 5, 2, 4, 2, 4, …
## $ Q10       <int> 4, 4, 2, 4, 4, 4, 5, 5, 2, 4, 2, 4, 4, 4, 3, 4, 4, 3, 2, 3, …
## $ Q11       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 3, 4, 4, 4, 4, 5, 4, 3, 3, …
## $ Q12       <int> 4, 4, 4, 4, 4, 4, 5, 5, 3, 4, 4, 3, 4, 3, 3, 4, 5, 4, 4, 2, …
## $ Q13       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 2, 4, 4, 4, 5, 4, 4, 4, …
## $ Q14       <int> 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 4, 5, 4, 5, 4, 4, 4, …
## $ Q15       <int> 4, 4, 3, 4, 4, 4, 4, 2, 3, 4, 4, 3, 1, 4, 4, 4, 5, 4, 4, 4, …
## $ Q16       <int> 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 4, 4, …
## $ Q17       <int> 4, 3, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 3, 2, 4, 5, 4, 4, 3, 4, …
## $ Q18       <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, …
## $ Q19       <int> 4, 2, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 1, 4, 4, 4, 5, 4, 2, 3, …
## $ Q20       <int> 4, 1, 3, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 2, 4, 5, 5, 4, 2, 4, …
## $ Gender1   <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, …
## $ EDU1      <int> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
str(df)
## 'data.frame':    1925 obs. of  26 variables:
##  $ Q1       : int  4 4 4 5 4 4 4 4 4 4 ...
##  $ Q2       : int  4 4 4 4 4 4 2 2 4 4 ...
##  $ Q3       : int  2 4 4 4 4 4 4 4 4 2 ...
##  $ Q4       : int  3 4 4 4 4 4 4 4 4 2 ...
##  $ Q5       : int  4 4 2 4 4 4 4 4 2 4 ...
##  $ Q6       : int  2 3 4 4 4 4 4 4 1 2 ...
##  $ Q7       : int  2 2 4 4 4 4 4 4 3 4 ...
##  $ Q8       : int  4 4 4 4 4 4 5 5 2 2 ...
##  $ Q9       : int  4 4 4 4 2 4 5 5 3 4 ...
##  $ Q10      : int  4 4 2 4 4 4 5 5 2 4 ...
##  $ Q11      : int  4 4 4 4 4 4 5 5 4 4 ...
##  $ Q12      : int  4 4 4 4 4 4 5 5 3 4 ...
##  $ Q13      : int  4 4 4 4 4 4 5 5 4 4 ...
##  $ Q14      : int  4 4 4 4 4 4 5 5 5 4 ...
##  $ Q15      : int  4 4 3 4 4 4 4 2 3 4 ...
##  $ Q16      : int  4 4 4 4 4 4 5 2 4 4 ...
##  $ Q17      : int  4 3 4 4 4 4 2 2 4 4 ...
##  $ Q18      : int  4 4 4 4 4 4 4 4 4 4 ...
##  $ Q19      : int  4 2 4 4 4 4 4 2 4 2 ...
##  $ Q20      : int  4 1 3 4 4 4 4 2 4 2 ...
##  $ Gender1  : int  0 0 0 0 0 0 0 0 1 0 ...
##  $ EDU1     : int  1 1 2 1 2 1 1 1 4 3 ...
##  $ BF       : num  3.4 4 3.6 4.2 4 4 3.6 3.6 3.6 3.2 ...
##  $ BM       : num  3.2 3.4 3.6 4 3.6 4 4.6 4.6 2.2 3.2 ...
##  $ Happiness: num  4 4 3.8 4 4 4 4.8 4.4 3.8 4 ...
##  $ Peace    : num  4 2.8 3.8 4 4 4 3.8 2.4 4 3.2 ...
head(df)
##   Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15 Q16 Q17 Q18 Q19 Q20
## 1  4  4  2  3  4  2  2  4  4   4   4   4   4   4   4   4   4   4   4   4
## 2  4  4  4  4  4  3  2  4  4   4   4   4   4   4   4   4   3   4   2   1
## 3  4  4  4  4  2  4  4  4  4   2   4   4   4   4   3   4   4   4   4   3
## 4  5  4  4  4  4  4  4  4  4   4   4   4   4   4   4   4   4   4   4   4
## 5  4  4  4  4  4  4  4  4  2   4   4   4   4   4   4   4   4   4   4   4
## 6  4  4  4  4  4  4  4  4  4   4   4   4   4   4   4   4   4   4   4   4
##   Gender1 EDU1  BF  BM Happiness Peace
## 1       0    1 3.4 3.2       4.0   4.0
## 2       0    1 4.0 3.4       4.0   2.8
## 3       0    2 3.6 3.6       3.8   3.8
## 4       0    1 4.2 4.0       4.0   4.0
## 5       0    2 4.0 3.6       4.0   4.0
## 6       0    1 4.0 4.0       4.0   4.0
tail(df)
##      Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Q11 Q12 Q13 Q14 Q15 Q16 Q17 Q18 Q19 Q20
## 1920  4  4  3  4  4  2  2  3  4   2   2   4   3   4   4   3   4   4   3   4
## 1921  2  2  2  1  2  2  2  2  2   2   1   3   2   1   3   2   2   2   2   2
## 1922  3  2  2  2  3  1  1  1  1   1   3   3   3   4   4   4   4   5   2   2
## 1923  5  4  4  4  4  2  2  2  2   3   3   4   3   4   3   3   3   4   4   4
## 1924  4  4  4  2  2  4  2  4  4   3   3   2   3   4   3   4   4   4   3   4
## 1925  3  3  1  1  2  1  1  1  1   1   4   4   3   2   2   3   4   4   3   2
##      Gender1 EDU1  BF  BM Happiness Peace
## 1920       1    3 3.8 2.6       3.4   3.6
## 1921       1    2 1.8 2.0       2.0   2.0
## 1922       0    2 2.4 1.0       3.4   3.4
## 1923       0    2 4.2 2.2       3.4   3.6
## 1924       1    2 3.2 3.4       3.0   3.8
## 1925       0    3 2.0 1.0       3.0   3.2
shapiro.test(df$Happiness)
## 
##  Shapiro-Wilk normality test
## 
## data:  df$Happiness
## W = 0.96442, p-value < 2.2e-16
# Peace, BM, 정규성 검정 실행해 보세요
options(scipen=100)
shapiro.test(df$Peace)
## 
##  Shapiro-Wilk normality test
## 
## data:  df$Peace
## W = 0.97095, p-value < 0.00000000000000022
shapiro.test(df$BM)
## 
##  Shapiro-Wilk normality test
## 
## data:  df$BM
## W = 0.98807, p-value = 0.00000000001537
wilcox.test(df$Happiness,mu=3.5)
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  df$Happiness
## V = 1029154, p-value = 0.000002782
## alternative hypothesis: true location is not equal to 3.5
par(mfrow=c(1,2))

hist(df$Happiness)
hist(df$BF)

hist(df$Peace)
boxplot(df$Happiness)

boxplot(df$Peace)
wilcox.test(df$Happiness-df$Peace)
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  df$Happiness - df$Peace
## V = 596154, p-value = 0.3322
## alternative hypothesis: true location is not equal to 0
par(mfrow=c(2,2))

hist(df$Happiness-df$Peace)
boxplot(df$Happiness-df$Peace)

wilcox.test(df$Happiness~df$Gender1)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  df$Happiness by df$Gender1
## W = 463050, p-value = 0.211
## alternative hypothesis: true location shift is not equal to 0
par(mfrow=c(1,1))

boxplot(df$Happiness~df$Gender1)
library(ggplot2)

data(diamonds)
# ctrl+shift+m %>% %>% %>% 
df<-read.csv("Data1.csv")
glimpse(df)
## Rows: 1,925
## Columns: 26
## $ Q1        <int> 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, …
## $ Q2        <int> 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 2, 2, …
## $ Q3        <int> 2, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 3, 2, 3, …
## $ Q4        <int> 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 2, 4, …
## $ Q5        <int> 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 4, 3, 1, 2, …
## $ Q6        <int> 2, 3, 4, 4, 4, 4, 4, 4, 1, 2, 2, 2, 4, 4, 3, 5, 2, 2, 1, 4, …
## $ Q7        <int> 2, 2, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 5, 4, 4, 5, 4, 3, 4, 4, …
## $ Q8        <int> 4, 4, 4, 4, 4, 4, 5, 5, 2, 2, 4, 4, 4, 4, 3, 5, 4, 2, 4, 4, …
## $ Q9        <int> 4, 4, 4, 4, 2, 4, 5, 5, 3, 4, 4, 4, 2, 2, 4, 5, 2, 4, 2, 4, …
## $ Q10       <int> 4, 4, 2, 4, 4, 4, 5, 5, 2, 4, 2, 4, 4, 4, 3, 4, 4, 3, 2, 3, …
## $ Q11       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 3, 4, 4, 4, 4, 5, 4, 3, 3, …
## $ Q12       <int> 4, 4, 4, 4, 4, 4, 5, 5, 3, 4, 4, 3, 4, 3, 3, 4, 5, 4, 4, 2, …
## $ Q13       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 2, 4, 4, 4, 5, 4, 4, 4, …
## $ Q14       <int> 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 4, 5, 4, 5, 4, 4, 4, …
## $ Q15       <int> 4, 4, 3, 4, 4, 4, 4, 2, 3, 4, 4, 3, 1, 4, 4, 4, 5, 4, 4, 4, …
## $ Q16       <int> 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 4, 4, …
## $ Q17       <int> 4, 3, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 3, 2, 4, 5, 4, 4, 3, 4, …
## $ Q18       <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, …
## $ Q19       <int> 4, 2, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 1, 4, 4, 4, 5, 4, 2, 3, …
## $ Q20       <int> 4, 1, 3, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 2, 4, 5, 5, 4, 2, 4, …
## $ Gender1   <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, …
## $ EDU1      <int> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
df %>% glimpse()
## Rows: 1,925
## Columns: 26
## $ Q1        <int> 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, …
## $ Q2        <int> 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 2, 2, …
## $ Q3        <int> 2, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 3, 2, 3, …
## $ Q4        <int> 3, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 2, 4, …
## $ Q5        <int> 4, 4, 2, 4, 4, 4, 4, 4, 2, 4, 4, 2, 4, 4, 4, 4, 4, 3, 1, 2, …
## $ Q6        <int> 2, 3, 4, 4, 4, 4, 4, 4, 1, 2, 2, 2, 4, 4, 3, 5, 2, 2, 1, 4, …
## $ Q7        <int> 2, 2, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 5, 4, 4, 5, 4, 3, 4, 4, …
## $ Q8        <int> 4, 4, 4, 4, 4, 4, 5, 5, 2, 2, 4, 4, 4, 4, 3, 5, 4, 2, 4, 4, …
## $ Q9        <int> 4, 4, 4, 4, 2, 4, 5, 5, 3, 4, 4, 4, 2, 2, 4, 5, 2, 4, 2, 4, …
## $ Q10       <int> 4, 4, 2, 4, 4, 4, 5, 5, 2, 4, 2, 4, 4, 4, 3, 4, 4, 3, 2, 3, …
## $ Q11       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 3, 4, 4, 4, 4, 5, 4, 3, 3, …
## $ Q12       <int> 4, 4, 4, 4, 4, 4, 5, 5, 3, 4, 4, 3, 4, 3, 3, 4, 5, 4, 4, 2, …
## $ Q13       <int> 4, 4, 4, 4, 4, 4, 5, 5, 4, 4, 4, 4, 2, 4, 4, 4, 5, 4, 4, 4, …
## $ Q14       <int> 4, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 3, 4, 5, 4, 5, 4, 4, 4, …
## $ Q15       <int> 4, 4, 3, 4, 4, 4, 4, 2, 3, 4, 4, 3, 1, 4, 4, 4, 5, 4, 4, 4, …
## $ Q16       <int> 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 4, 4, …
## $ Q17       <int> 4, 3, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 3, 2, 4, 5, 4, 4, 3, 4, …
## $ Q18       <int> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 2, 4, 4, 4, …
## $ Q19       <int> 4, 2, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 1, 4, 4, 4, 5, 4, 2, 3, …
## $ Q20       <int> 4, 1, 3, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 2, 4, 5, 5, 4, 2, 4, …
## $ Gender1   <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, …
## $ EDU1      <int> 1, 1, 2, 1, 2, 1, 1, 1, 4, 3, 2, 1, 1, 3, 3, 2, 1, 1, 1, 4, …
## $ BF        <dbl> 3.4, 4.0, 3.6, 4.2, 4.0, 4.0, 3.6, 3.6, 3.6, 3.2, 4.0, 3.2, …
## $ BM        <dbl> 3.2, 3.4, 3.6, 4.0, 3.6, 4.0, 4.6, 4.6, 2.2, 3.2, 3.2, 3.6, …
## $ Happiness <dbl> 4.0, 4.0, 3.8, 4.0, 4.0, 4.0, 4.8, 4.4, 3.8, 4.0, 4.0, 3.4, …
## $ Peace     <dbl> 4.0, 2.8, 3.8, 4.0, 4.0, 4.0, 3.8, 2.4, 4.0, 3.2, 4.0, 3.9, …
names(diamonds)
##  [1] "carat"   "cut"     "color"   "clarity" "depth"   "table"   "price"  
##  [8] "x"       "y"       "z"
diamonds1<-diamonds %>% rename(ca=clarity,pr=price) 
names(diamonds1)
##  [1] "carat" "cut"   "color" "ca"    "depth" "table" "pr"    "x"     "y"    
## [10] "z"
glimpse(diamonds)
## Rows: 53,940
## Columns: 10
## $ carat   <dbl> 0.23, 0.21, 0.23, 0.29, 0.31, 0.24, 0.24, 0.26, 0.22, 0.23, 0.…
## $ cut     <ord> Ideal, Premium, Good, Premium, Good, Very Good, Very Good, Ver…
## $ color   <ord> E, E, E, I, J, J, I, H, E, H, J, J, F, J, E, E, I, J, J, J, I,…
## $ clarity <ord> SI2, SI1, VS1, VS2, SI2, VVS2, VVS1, SI1, VS2, VS1, SI1, VS1, …
## $ depth   <dbl> 61.5, 59.8, 56.9, 62.4, 63.3, 62.8, 62.3, 61.9, 65.1, 59.4, 64…
## $ table   <dbl> 55, 61, 65, 58, 58, 57, 57, 55, 61, 61, 55, 56, 61, 54, 62, 58…
## $ price   <int> 326, 326, 327, 334, 335, 336, 336, 337, 337, 338, 339, 340, 34…
## $ x       <dbl> 3.95, 3.89, 4.05, 4.20, 4.34, 3.94, 3.95, 4.07, 3.87, 4.00, 4.…
## $ y       <dbl> 3.98, 3.84, 4.07, 4.23, 4.35, 3.96, 3.98, 4.11, 3.78, 4.05, 4.…
## $ z       <dbl> 2.43, 2.31, 2.31, 2.63, 2.75, 2.48, 2.47, 2.53, 2.49, 2.39, 2.…
diamonds %>% select(carat,price)
## # A tibble: 53,940 × 2
##    carat price
##    <dbl> <int>
##  1  0.23   326
##  2  0.21   326
##  3  0.23   327
##  4  0.29   334
##  5  0.31   335
##  6  0.24   336
##  7  0.24   336
##  8  0.26   337
##  9  0.22   337
## 10  0.23   338
## # … with 53,930 more rows
diamonds %>% select(1:4)
## # A tibble: 53,940 × 4
##    carat cut       color clarity
##    <dbl> <ord>     <ord> <ord>  
##  1  0.23 Ideal     E     SI2    
##  2  0.21 Premium   E     SI1    
##  3  0.23 Good      E     VS1    
##  4  0.29 Premium   I     VS2    
##  5  0.31 Good      J     SI2    
##  6  0.24 Very Good J     VVS2   
##  7  0.24 Very Good I     VVS1   
##  8  0.26 Very Good H     SI1    
##  9  0.22 Fair      E     VS2    
## 10  0.23 Very Good H     VS1    
## # … with 53,930 more rows
diamonds %>% slice(1:5)
## # A tibble: 5 × 10
##   carat cut     color clarity depth table price     x     y     z
##   <dbl> <ord>   <ord> <ord>   <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1  0.23 Ideal   E     SI2      61.5    55   326  3.95  3.98  2.43
## 2  0.21 Premium E     SI1      59.8    61   326  3.89  3.84  2.31
## 3  0.23 Good    E     VS1      56.9    65   327  4.05  4.07  2.31
## 4  0.29 Premium I     VS2      62.4    58   334  4.2   4.23  2.63
## 5  0.31 Good    J     SI2      63.3    58   335  4.34  4.35  2.75
diamonds %>% filter(cut=="Good")
## # A tibble: 4,906 × 10
##    carat cut   color clarity depth table price     x     y     z
##    <dbl> <ord> <ord> <ord>   <dbl> <dbl> <int> <dbl> <dbl> <dbl>
##  1  0.23 Good  E     VS1      56.9    65   327  4.05  4.07  2.31
##  2  0.31 Good  J     SI2      63.3    58   335  4.34  4.35  2.75
##  3  0.3  Good  J     SI1      64      55   339  4.25  4.28  2.73
##  4  0.3  Good  J     SI1      63.4    54   351  4.23  4.29  2.7 
##  5  0.3  Good  J     SI1      63.8    56   351  4.23  4.26  2.71
##  6  0.3  Good  I     SI2      63.3    56   351  4.26  4.3   2.71
##  7  0.23 Good  F     VS1      58.2    59   402  4.06  4.08  2.37
##  8  0.23 Good  E     VS1      64.1    59   402  3.83  3.85  2.46
##  9  0.31 Good  H     SI1      64      54   402  4.29  4.31  2.75
## 10  0.26 Good  D     VS2      65.2    56   403  3.99  4.02  2.61
## # … with 4,896 more rows
table(diamonds$cut)
## 
##      Fair      Good Very Good   Premium     Ideal 
##      1610      4906     12082     13791     21551
diamonds %>% filter(price==min(price))
## # A tibble: 2 × 10
##   carat cut     color clarity depth table price     x     y     z
##   <dbl> <ord>   <ord> <ord>   <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1  0.23 Ideal   E     SI2      61.5    55   326  3.95  3.98  2.43
## 2  0.21 Premium E     SI1      59.8    61   326  3.89  3.84  2.31
diamonds %>% filter(cut%in%c("ldeal","Good"))
## # A tibble: 4,906 × 10
##    carat cut   color clarity depth table price     x     y     z
##    <dbl> <ord> <ord> <ord>   <dbl> <dbl> <int> <dbl> <dbl> <dbl>
##  1  0.23 Good  E     VS1      56.9    65   327  4.05  4.07  2.31
##  2  0.31 Good  J     SI2      63.3    58   335  4.34  4.35  2.75
##  3  0.3  Good  J     SI1      64      55   339  4.25  4.28  2.73
##  4  0.3  Good  J     SI1      63.4    54   351  4.23  4.29  2.7 
##  5  0.3  Good  J     SI1      63.8    56   351  4.23  4.26  2.71
##  6  0.3  Good  I     SI2      63.3    56   351  4.26  4.3   2.71
##  7  0.23 Good  F     VS1      58.2    59   402  4.06  4.08  2.37
##  8  0.23 Good  E     VS1      64.1    59   402  3.83  3.85  2.46
##  9  0.31 Good  H     SI1      64      54   402  4.29  4.31  2.75
## 10  0.26 Good  D     VS2      65.2    56   403  3.99  4.02  2.61
## # … with 4,896 more rows