Variables

# variable assignment is done by "<-" (or in some cases by "=")
age <- 42
# all variables are mutable
age <- 21
age <- age + 1
# R has the dynamic typing discipline
age <- "2"

Operations

# help
?abs
??sqrt

# raise to power
2**3
[1] 8
2^3
[1] 8
# operator precedence, the use of parentheses
2^(3+1)
[1] 16
x <- 2
exp(x)
[1] 7.389056
log(x)
[1] 0.6931472
?log
log10(100)
[1] 2
# logical operations
x >= 3
[1] FALSE
x == 2
[1] TRUE
x != 2
[1] FALSE
x != 2 | TRUE
[1] TRUE
!((TRUE | FALSE) & (TRUE & FALSE))
[1] TRUE
y = !((TRUE | FALSE) & (TRUE & FALSE))

TRUE
[1] TRUE
10
[1] 10
10.0
[1] 10
"female"
[1] "female"

Data structures

# vectors
?c
colors <- c("red", "green", "blue")
# Python, C: colros = ["red", "green", "blue"]

numbers <- c(1, 10, 100)
log10(numbers)
[1] 0 1 2
c(1:3) + log10(numbers)
[1] 1 3 5
?c

colors[1]
[1] "red"
colors[1:3]
[1] "red"   "green" "blue" 
colors[2:3]
[1] "green" "blue" 
colors[c(1,3)]
[1] "red"  "blue"
colors[-c(1,3)]
[1] "green"
temperatures <- c(17.5, 18, 18.5)
temperatures[temperatures >= 18]
[1] 18.0 18.5
?mean
mean(temperatures)
[1] 18
demeaned <- temperatures - mean(temperatures)
demeaned
[1] -0.5  0.0  0.5
?sd
sd(temperatures)
[1] 0.5
demeaned / sd(temperatures)
[1] -1  0  1
# factors
?factor
factor(colors)
[1] red   green blue 
Levels: blue green red
summary(colors)
   Length     Class      Mode 
        3 character character 
colors <- factor(colors)
colors
[1] red   green blue 
Levels: blue green red
summary(colors)
 blue green   red 
    1     1     1 
gender_samples <- factor(c("female", "male", "female", "female"))
summary(gender_samples)
female   male 
     3      1 

Data frames

?read.table
?read.csv

df <- read.csv("evaluations.csv")
df

?head
head(df)
tail(df)

str(df)
'data.frame':   463 obs. of  21 variables:
 $ score        : num  4.7 4.1 3.9 4.8 4.6 4.3 2.8 4.1 3.4 4.5 ...
 $ rank         : chr  "tenure track" "tenure track" "tenure track" "tenure track" ...
 $ ethnicity    : chr  "minority" "minority" "minority" "minority" ...
 $ gender       : chr  "female" "female" "female" "female" ...
 $ language     : chr  "english" "english" "english" "english" ...
 $ age          : int  36 36 36 36 59 59 59 51 51 40 ...
 $ cls_perc_eval: num  55.8 68.8 60.8 62.6 85 ...
 $ cls_did_eval : int  24 86 76 77 17 35 39 55 111 40 ...
 $ cls_students : int  43 125 125 123 20 40 44 55 195 46 ...
 $ cls_level    : chr  "upper" "upper" "upper" "upper" ...
 $ cls_profs    : chr  "single" "single" "single" "single" ...
 $ cls_credits  : chr  "multi credit" "multi credit" "multi credit" "multi credit" ...
 $ bty_f1lower  : int  5 5 5 5 4 4 4 5 5 2 ...
 $ bty_f1upper  : int  7 7 7 7 4 4 4 2 2 5 ...
 $ bty_f2upper  : int  6 6 6 6 2 2 2 5 5 4 ...
 $ bty_m1lower  : int  2 2 2 2 2 2 2 2 2 3 ...
 $ bty_m1upper  : int  4 4 4 4 3 3 3 3 3 3 ...
 $ bty_m2upper  : int  6 6 6 6 3 3 3 3 3 2 ...
 $ bty_avg      : num  5 5 5 5 3 ...
 $ pic_outfit   : chr  "not formal" "not formal" "not formal" "not formal" ...
 $ pic_color    : chr  "color" "color" "color" "color" ...
names(df)
 [1] "score"         "rank"          "ethnicity"     "gender"       
 [5] "language"      "age"           "cls_perc_eval" "cls_did_eval" 
 [9] "cls_students"  "cls_level"     "cls_profs"     "cls_credits"  
[13] "bty_f1lower"   "bty_f1upper"   "bty_f2upper"   "bty_m1lower"  
[17] "bty_m1upper"   "bty_m2upper"   "bty_avg"       "pic_outfit"   
[21] "pic_color"    
summary(df)
     score           rank            ethnicity            gender         
 Min.   :2.300   Length:463         Length:463         Length:463        
 1st Qu.:3.800   Class :character   Class :character   Class :character  
 Median :4.300   Mode  :character   Mode  :character   Mode  :character  
 Mean   :4.175                                                           
 3rd Qu.:4.600                                                           
 Max.   :5.000                                                           
   language              age        cls_perc_eval     cls_did_eval   
 Length:463         Min.   :29.00   Min.   : 10.42   Min.   :  5.00  
 Class :character   1st Qu.:42.00   1st Qu.: 62.70   1st Qu.: 15.00  
 Mode  :character   Median :48.00   Median : 76.92   Median : 23.00  
                    Mean   :48.37   Mean   : 74.43   Mean   : 36.62  
                    3rd Qu.:57.00   3rd Qu.: 87.25   3rd Qu.: 40.00  
                    Max.   :73.00   Max.   :100.00   Max.   :380.00  
  cls_students     cls_level          cls_profs        
 Min.   :  8.00   Length:463         Length:463        
 1st Qu.: 19.00   Class :character   Class :character  
 Median : 29.00   Mode  :character   Mode  :character  
 Mean   : 55.18                                        
 3rd Qu.: 60.00                                        
 Max.   :581.00                                        
 cls_credits         bty_f1lower     bty_f1upper     bty_f2upper    
 Length:463         Min.   :1.000   Min.   :1.000   Min.   : 1.000  
 Class :character   1st Qu.:2.000   1st Qu.:4.000   1st Qu.: 4.000  
 Mode  :character   Median :4.000   Median :5.000   Median : 5.000  
                    Mean   :3.963   Mean   :5.019   Mean   : 5.214  
                    3rd Qu.:5.000   3rd Qu.:7.000   3rd Qu.: 6.000  
                    Max.   :8.000   Max.   :9.000   Max.   :10.000  
  bty_m1lower     bty_m1upper     bty_m2upper       bty_avg     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.667  
 1st Qu.:2.000   1st Qu.:3.000   1st Qu.:4.000   1st Qu.:3.167  
 Median :3.000   Median :4.000   Median :5.000   Median :4.333  
 Mean   :3.413   Mean   :4.147   Mean   :4.752   Mean   :4.418  
 3rd Qu.:5.000   3rd Qu.:5.000   3rd Qu.:6.000   3rd Qu.:5.500  
 Max.   :7.000   Max.   :9.000   Max.   :9.000   Max.   :8.167  
  pic_outfit         pic_color        
 Length:463         Length:463        
 Class :character   Class :character  
 Mode  :character   Mode  :character  
                                      
                                      
                                      
df$gender
  [1] "female" "female" "female" "female" "male"   "male"   "male"  
  [8] "male"   "male"   "female" "female" "female" "female" "female"
 [15] "female" "female" "female" "female" "female" "female" "female"
 [22] "female" "female" "male"   "male"   "male"   "male"   "male"  
 [29] "male"   "male"   "female" "female" "female" "female" "female"
 [36] "female" "female" "female" "female" "female" "female" "female"
 [43] "female" "female" "female" "female" "female" "female" "female"
 [50] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
 [57] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
 [64] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
 [71] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
 [78] "male"   "female" "female" "female" "female" "male"   "male"  
 [85] "male"   "male"   "male"   "male"   "female" "female" "female"
 [92] "female" "female" "male"   "male"   "male"   "male"   "male"  
 [99] "male"   "male"   "male"   "female" "female" "female" "female"
[106] "female" "female" "female" "female" "female" "female" "female"
[113] "female" "female" "female" "female" "female" "female" "female"
[120] "female" "female" "female" "female" "female" "female" "female"
[127] "female" "male"   "male"   "male"   "male"   "male"   "male"  
[134] "male"   "male"   "male"   "male"   "male"   "male"   "female"
[141] "female" "male"   "male"   "male"   "male"   "male"   "male"  
[148] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[155] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[162] "female" "male"   "male"   "male"   "male"   "male"   "male"  
[169] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[176] "male"   "male"   "female" "female" "female" "female" "female"
[183] "female" "female" "female" "female" "female" "female" "female"
[190] "female" "male"   "male"   "male"   "female" "female" "female"
[197] "female" "male"   "male"   "male"   "male"   "male"   "male"  
[204] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[211] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[218] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[225] "male"   "male"   "female" "female" "female" "female" "male"  
[232] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[239] "male"   "male"   "female" "female" "female" "female" "female"
[246] "female" "female" "female" "female" "female" "female" "male"  
[253] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[260] "male"   "male"   "male"   "male"   "male"   "female" "female"
[267] "female" "female" "female" "female" "male"   "male"   "male"  
[274] "male"   "female" "female" "female" "female" "female" "female"
[281] "female" "female" "female" "female" "female" "female" "female"
[288] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[295] "male"   "female" "female" "female" "female" "female" "female"
[302] "female" "female" "female" "female" "female" "female" "male"  
[309] "male"   "female" "female" "female" "male"   "male"   "female"
[316] "female" "female" "female" "female" "female" "female" "female"
[323] "female" "female" "female" "female" "male"   "male"   "male"  
[330] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[337] "male"   "female" "male"   "male"   "male"   "male"   "male"  
[344] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[351] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[358] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[365] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[372] "male"   "female" "female" "female" "female" "female" "female"
[379] "female" "female" "female" "female" "male"   "male"   "male"  
[386] "male"   "male"   "male"   "male"   "female" "female" "female"
[393] "female" "male"   "male"   "male"   "male"   "male"   "male"  
[400] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[407] "male"   "male"   "female" "female" "female" "female" "female"
[414] "female" "female" "female" "female" "female" "male"   "male"  
[421] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[428] "male"   "male"   "male"   "male"   "male"   "male"   "male"  
[435] "male"   "male"   "male"   "male"   "female" "female" "female"
[442] "male"   "male"   "female" "female" "female" "female" "female"
[449] "female" "female" "female" "female" "female" "male"   "male"  
[456] "male"   "male"   "male"   "male"   "female" "female" "female"
[463] "female"
df$gender[55]
[1] "male"
# factorizing
df$gender = factor(df$gender)
summary(df)
     score           rank            ethnicity            gender   
 Min.   :2.300   Length:463         Length:463         female:195  
 1st Qu.:3.800   Class :character   Class :character   male  :268  
 Median :4.300   Mode  :character   Mode  :character               
 Mean   :4.175                                                     
 3rd Qu.:4.600                                                     
 Max.   :5.000                                                     
   language              age        cls_perc_eval     cls_did_eval   
 Length:463         Min.   :29.00   Min.   : 10.42   Min.   :  5.00  
 Class :character   1st Qu.:42.00   1st Qu.: 62.70   1st Qu.: 15.00  
 Mode  :character   Median :48.00   Median : 76.92   Median : 23.00  
                    Mean   :48.37   Mean   : 74.43   Mean   : 36.62  
                    3rd Qu.:57.00   3rd Qu.: 87.25   3rd Qu.: 40.00  
                    Max.   :73.00   Max.   :100.00   Max.   :380.00  
  cls_students     cls_level          cls_profs        
 Min.   :  8.00   Length:463         Length:463        
 1st Qu.: 19.00   Class :character   Class :character  
 Median : 29.00   Mode  :character   Mode  :character  
 Mean   : 55.18                                        
 3rd Qu.: 60.00                                        
 Max.   :581.00                                        
 cls_credits         bty_f1lower     bty_f1upper     bty_f2upper    
 Length:463         Min.   :1.000   Min.   :1.000   Min.   : 1.000  
 Class :character   1st Qu.:2.000   1st Qu.:4.000   1st Qu.: 4.000  
 Mode  :character   Median :4.000   Median :5.000   Median : 5.000  
                    Mean   :3.963   Mean   :5.019   Mean   : 5.214  
                    3rd Qu.:5.000   3rd Qu.:7.000   3rd Qu.: 6.000  
                    Max.   :8.000   Max.   :9.000   Max.   :10.000  
  bty_m1lower     bty_m1upper     bty_m2upper       bty_avg     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.667  
 1st Qu.:2.000   1st Qu.:3.000   1st Qu.:4.000   1st Qu.:3.167  
 Median :3.000   Median :4.000   Median :5.000   Median :4.333  
 Mean   :3.413   Mean   :4.147   Mean   :4.752   Mean   :4.418  
 3rd Qu.:5.000   3rd Qu.:5.000   3rd Qu.:6.000   3rd Qu.:5.500  
 Max.   :7.000   Max.   :9.000   Max.   :9.000   Max.   :8.167  
  pic_outfit         pic_color        
 Length:463         Length:463        
 Class :character   Class :character  
 Mode  :character   Mode  :character  
                                      
                                      
                                      
# filtering
df$gender == "female"
  [1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
 [12]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 [23]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE
 [34]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 [45]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
 [56] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [67] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [78] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
 [89]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
[100] FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[111]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[122]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
[133] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE
[144] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[155] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
[166] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[177] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[188]  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
[199] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[210] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[221] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
[232] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[243]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
[254] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[265]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE
[276]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[287]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[298]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE
[309] FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[320]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
[331] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
[342] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[353] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[364] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[375]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE
[386] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE
[397] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[408] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[419] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[430] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[441]  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[452]  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE
[463]  TRUE
head(df)
head(df[df$gender == "female",])
head(df[df$gender == "female",1])
[1] 4.7 4.1 3.9 4.8 4.5 3.8
head(df[df$gender == "female",c(1:3)])
head(df[df$gender == "female" & df$score > 4.7,])

# subsetting
?subset
df$gender == "female"
  [1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
 [12]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 [23]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE
 [34]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 [45]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
 [56] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [67] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [78] FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
 [89]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE
[100] FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[111]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[122]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
[133] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE
[144] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[155] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
[166] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[177] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[188]  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
[199] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[210] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[221] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
[232] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[243]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
[254] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[265]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE
[276]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[287]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[298]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE
[309] FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[320]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
[331] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
[342] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[353] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[364] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[375]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE
[386] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE
[397] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[408] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[419] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[430] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE
[441]  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[452]  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE
[463]  TRUE
head(subset(df, df$gender == "female"))

female_df <- subset(df, df$gender == "female")
male_df <- subset(df, df$gender == "male")

?rbind
?cbind

rbind(head(female_df, n=3), head(male_df, n=3))

new_df <- rbind(head(female_df, n=3), head(male_df, n=3))
summary(new_df)
     score           rank            ethnicity            gender 
 Min.   :2.800   Length:6           Length:6           female:3  
 1st Qu.:3.950   Class :character   Class :character   male  :3  
 Median :4.200   Mode  :character   Mode  :character             
 Mean   :4.067                                                   
 3rd Qu.:4.525                                                   
 Max.   :4.700                                                   
   language              age       cls_perc_eval    cls_did_eval  
 Length:6           Min.   :36.0   Min.   :55.81   Min.   :17.00  
 Class :character   1st Qu.:36.0   1st Qu.:62.80   1st Qu.:26.75  
 Mode  :character   Median :47.5   Median :76.90   Median :37.00  
                    Mean   :47.5   Mean   :74.43   Mean   :46.17  
                    3rd Qu.:59.0   3rd Qu.:86.88   3rd Qu.:66.75  
                    Max.   :59.0   Max.   :88.64   Max.   :86.00  
  cls_students     cls_level          cls_profs        
 Min.   : 20.00   Length:6           Length:6          
 1st Qu.: 40.75   Class :character   Class :character  
 Median : 43.50   Mode  :character   Mode  :character  
 Mean   : 66.17                                        
 3rd Qu.:104.75                                        
 Max.   :125.00                                        
 cls_credits         bty_f1lower   bty_f1upper   bty_f2upper  bty_m1lower
 Length:6           Min.   :4.0   Min.   :4.0   Min.   :2    Min.   :2   
 Class :character   1st Qu.:4.0   1st Qu.:4.0   1st Qu.:2    1st Qu.:2   
 Mode  :character   Median :4.5   Median :5.5   Median :4    Median :2   
                    Mean   :4.5   Mean   :5.5   Mean   :4    Mean   :2   
                    3rd Qu.:5.0   3rd Qu.:7.0   3rd Qu.:6    3rd Qu.:2   
                    Max.   :5.0   Max.   :7.0   Max.   :6    Max.   :2   
  bty_m1upper   bty_m2upper     bty_avg   pic_outfit       
 Min.   :3.0   Min.   :3.0   Min.   :3   Length:6          
 1st Qu.:3.0   1st Qu.:3.0   1st Qu.:3   Class :character  
 Median :3.5   Median :4.5   Median :4   Mode  :character  
 Mean   :3.5   Mean   :4.5   Mean   :4                     
 3rd Qu.:4.0   3rd Qu.:6.0   3rd Qu.:5                     
 Max.   :4.0   Max.   :6.0   Max.   :5                     
  pic_color        
 Length:6          
 Class :character  
 Mode  :character  
                   
                   
                   
head(cbind(df[,1:2], df[,5:6]))
LS0tCnRpdGxlOiAiSW50cm9kdWN0aW9uIGludG8gUiIKb3V0cHV0OgogIGh0bWxfbm90ZWJvb2s6CiAgICBjb2RlX2ZvbGRpbmc6IHNob3cKICAgIGZpZ19jYXB0aW9uOiB5ZXMKICAgIHRoZW1lOiB1bml0ZWQKICAgIHRvYzogeWVzCi0tLQoKIyMgVmFyaWFibGVzCgpgYGB7cn0KIyB2YXJpYWJsZSBhc3NpZ25tZW50IGlzIGRvbmUgYnkgIjwtIiAob3IgaW4gc29tZSBjYXNlcyBieSAiPSIpCmFnZSA8LSA0MgojIGFsbCB2YXJpYWJsZXMgYXJlIG11dGFibGUKYWdlIDwtIDIxCmFnZSA8LSBhZ2UgKyAxCiMgUiBoYXMgdGhlIGR5bmFtaWMgdHlwaW5nIGRpc2NpcGxpbmUKYWdlIDwtICIyIgpgYGAKCiMjIE9wZXJhdGlvbnMKCmBgYHtyfQojI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