3 Variables

As mentioned, we often need some number (eg a concentration), some table (eg table of differentially expressed genes), information (eg the name of a protein) etc. to be saved in R to be able to use them later in the analysis. This is where variables come into play, and now we’ll see how to create them, how to reuse them, and what kinds of variables exist.

Create a variable

To create a variable we write name_of_the_variable <- what_to_save (you can either use = instead of <-, even if the former is usually used for declaring arguments in a function, but we’ll see it later).
Now, write this to the console, click Return/send on the keyborard, and see what happens:

myvar <- 5

On the console nothing happens, but something appeared in the window called Environment (if yours is different, it may be that there is the “List” view setting instead of “Grid” in the blue box, you can change it to your liking).

Here in details the info given for each variable:

  • Name: name of the variable
  • Type: type of the variable (don’t worry, we’ll see in a minute what this means)
  • Length:: the length of the variable (how many items it contains)
  • Size: how much memory that variable occupies
  • Value: the value of our variable

If we want to create multiple variables with the same value we can do this:

var1 <- var2 <- var3 <- 20
print(var1)
[1] 20
print(var2)
[1] 20
print(var3)
[1] 20

Use a variable

Ok, but once stored, how to we use a variable? Easy, we just need to type it in the console (or start writing the first letters of its name and press Tab to show RStudio suggestions). If, for example, we want to calculate the power of our variable we should write:

myvar ** 2
[1] 25

And here is the result (to elevate to the power we can either use ** or ^).
And what if we want to store this result? As before:

myvar_power <- myvar ** 2
print(myvar_power)
[1] 25

Here we use print() function, but in R we can also just write the name of the variable to see it.

Variable names

As in everything, even in naming variables there are rules and guidelines. Don’t be scared, they are simple and will make your life easier, let’s see them together.

Rules:

  • Variable name CANNOT start with a character other than a letter
  • Variable name can contain both letters and numbers (case sensitive, uppercase and lowercase matter)
  • Variable name may contain as special characters only the dot . or the underscore _

Guidelines:

  • Since the name of the variable must be useful, its name must suggest something: for example, the variable myvar was previously defined, whose meaning is equal to 0 (so avoid these names), while myvar_power is more indicative, as it tells us that it is raised to a power
  • Variables are normally written in lowercase letters, except for those you want to remain constant in your analysis, which in other languages are written in uppercase (this does not make them immutable, but suggests this feature within the script)
  • Use underscores rather than periods as special characters in variable names if you can
  • If the variable name contains more than one word, you can separate them with an underscore (as in the example) or use the camel case (myvarPower) or the Pascal case (MyvarPower)
  • Be consistent within the script: if you decide to use the Pascal case, always use the Pascal case in that script

Overwriting variables

Attention! Variables can be overwritten (unrecoverable action).
To override a variable, simply assign that variable a new value:

print(myvar)
[1] 5
myvar <- 9

print(myvar)
[1] 9

Now myvar is equal to 9, and there is no way back…
This feature is useful for saving space and not cluttering up too much with variables that are okay to change often, but it can be risky. So be careful when naming variables.

List all variables

A useful way to avoid overwriting an important variable is to list the variables. We know that in RStudio they are all present in the Environment window, but what if we weren’t in RStudio but elsewhere (for example in the terminal)?
The answer is simple, let’s use the ls() function

ls()
  [1] "aa_num"                         "abbreviations"                 
  [3] "age"                            "age_inf_threshold"             
  [5] "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                       
  [9] "aod_pmi_all"                    "aod_pmi_arr"                   
 [11] "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"             
 [15] "area_df"                        "areas"                         
 [17] "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                           
 [21] "ch3"                            "ch4"                           
 [23] "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                        
 [27] "common_all"                     "common_mean"                   
 [29] "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                  
 [33] "CXCR4"                          "description"                   
 [35] "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                   
 [39] "df_grouped"                     "df_male_ctrl_cdr4"             
 [41] "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                      
 [45] "dunn_res"                       "dunn_stat_df"                  
 [47] "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                   
 [51] "expr_mat_pat"                   "expr_values"                   
 [53] "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"         
 [57] "female_15_task1yes_expected"    "female_15_task1yes_max_cat"    
 [59] "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size"
 [63] "female_15_task1yes_table"       "female_t1_weight_bartlett"     
 [65] "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"      
 [69] "females_t1_task3_bartlett"      "females_t1_task3_boxplot"      
 [71] "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                     
 [75] "gene"                           "gene_2_keep"                   
 [77] "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                         
 [81] "grep_1"                         "grep_2"                        
 [83] "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                       
 [87] "idx"                            "interaction_factor"            
 [89] "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                           
 [93] "LHX9"                           "male_3_task2yes_df"            
 [95] "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"       
 [99] "male_3_task2yes_mosaic"         "male_3_task2yes_sample_size"   
[101] "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"               
[105] "male_3_task3_max"               "male_3_task3_shapiro"          
[107] "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"    
[111] "male_30_task3_qq"               "male_30_task3_qq_filt"         
[113] "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"   
[117] "male_30_weight_qq"              "male_30_weight_qq_filt"        
[119] "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                      
[123] "mean_col"                       "mean_res_better"               
[125] "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                     
[129] "mice1"                          "mice2"                         
[131] "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                     
[135] "mother_diabetes"                "mt_mat"                        
[137] "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                     
[141] "my_matrix2"                     "my_max"                        
[143] "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                        
[147] "my_vector"                      "mychar_d"                      
[149] "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                         
[153] "myvar_power"                    "n_15"                          
[155] "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                      
[159] "n_rep"                          "n_responders"                  
[161] "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                      
[165] "no_seed2"                       "non_norm_sample"               
[167] "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                   
[171] "norm_sample_density"            "norm_sample_ks_res"            
[173] "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                          
[177] "num2"                           "only_1"                        
[179] "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                   
[183] "patien2_sub"                    "patien3_sub"                   
[185] "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                      
[189] "patient2"                       "patient3"                      
[191] "pattern_to_check_1"             "pattern_to_check_2"            
[193] "perc_mito"                      "perc_no_mito"                  
[195] "pmi_thresh"                     "proteins"                      
[197] "proteins1"                      "proteins2"                     
[199] "PTPN7"                          "pvalue"                        
[201] "pvalue_to_plot"                 "quantiles"                     
[203] "r_numb"                         "r_patients"                    
[205] "read_sum_gene"                  "read_sum_pat"                  
[207] "read_sum_pat_filt"              "rep1"                          
[209] "rep2"                           "rep3"                          
[211] "response"                       "rin_area_boxplot"              
[213] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"       
[215] "rin_area_boxplots_arr"          "sample"                        
[217] "sample0"                        "sample1"                       
[219] "sample1_fr"                     "sample2"                       
[221] "sample2_fr"                     "sample3"                       
[223] "sample3_fr"                     "sd_calc"                       
[225] "sd_calc_ceil"                   "sd_calc_floor"                 
[227] "sd_calc_round"                  "sd_time"                       
[229] "sex"                            "sex_bar_arr"                   
[231] "sex_barplot"                    "sex_df"                        
[233] "sliced_odd"                     "sub_only"                      
[235] "sum_aa"                         "sum_tbl_sex"                   
[237] "sum_time"                       "sum_weights"                   
[239] "t_test_res"                     "t_value"                       
[241] "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[243] "t1_3_weight_df"                 "t1_3_weight_max"               
[245] "t1_3_weight_shapiro"            "Task3_bartlett_result"         
[247] "Task3_max_label"                "tbl_sex"                       
[249] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"      
[251] "tbl_sex_diagnosis_rowsum"       "time"                          
[253] "to_extract"                     "to_print"                      
[255] "total_mito"                     "total_no_mito"                 
[257] "treatment"                      "tukey_res"                     
[259] "untreated_chisq_res"            "untreated_cramer"              
[261] "untreated_df"                   "untreated_max_cat"             
[263] "untreated_mosaic"               "untreated_sample_size"         
[265] "untreated_table"                "untreated_weight_bartlett"     
[267] "untreated_weight_boxplot"       "untreated_weight_df"           
[269] "untreated_weight_lineplot"      "untreated_weight_shapiro"      
[271] "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[273] "upregulated_1"                  "upregulated_2"                 
[275] "var_calc"                       "var1"                          
[277] "var2"                           "var3"                          
[279] "weight"                         "weight_bartlett_result"        
[281] "weight_c"                       "weight_data"                   
[283] "weight_max_label"               "weight_n"                      
[285] "weight_sup_threshold"           "welch_res"                     
[287] "with_seed1"                     "with_seed2"                    

Here are our variables.
Note how I called this command with the name function: we will cover this concept later, for now you just need to know that they exist and that they can be identified immediately by the fact that after the name there is a pair of round brackets.

Delete variables

To delete a variable, use the rm() function and insert the variable to be deleted:

# create a variable
to_remove <- 1213

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                 
  [3] "age"                            "age_inf_threshold"             
  [5] "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                       
  [9] "aod_pmi_all"                    "aod_pmi_arr"                   
 [11] "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"             
 [15] "area_df"                        "areas"                         
 [17] "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                           
 [21] "ch3"                            "ch4"                           
 [23] "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                        
 [27] "common_all"                     "common_mean"                   
 [29] "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                  
 [33] "CXCR4"                          "description"                   
 [35] "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                   
 [39] "df_grouped"                     "df_male_ctrl_cdr4"             
 [41] "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                      
 [45] "dunn_res"                       "dunn_stat_df"                  
 [47] "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                   
 [51] "expr_mat_pat"                   "expr_values"                   
 [53] "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"         
 [57] "female_15_task1yes_expected"    "female_15_task1yes_max_cat"    
 [59] "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size"
 [63] "female_15_task1yes_table"       "female_t1_weight_bartlett"     
 [65] "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"      
 [69] "females_t1_task3_bartlett"      "females_t1_task3_boxplot"      
 [71] "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                     
 [75] "gene"                           "gene_2_keep"                   
 [77] "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                         
 [81] "grep_1"                         "grep_2"                        
 [83] "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                       
 [87] "idx"                            "interaction_factor"            
 [89] "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                           
 [93] "LHX9"                           "male_3_task2yes_df"            
 [95] "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"       
 [99] "male_3_task2yes_mosaic"         "male_3_task2yes_sample_size"   
[101] "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"               
[105] "male_3_task3_max"               "male_3_task3_shapiro"          
[107] "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"    
[111] "male_30_task3_qq"               "male_30_task3_qq_filt"         
[113] "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"   
[117] "male_30_weight_qq"              "male_30_weight_qq_filt"        
[119] "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                      
[123] "mean_col"                       "mean_res_better"               
[125] "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                     
[129] "mice1"                          "mice2"                         
[131] "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                     
[135] "mother_diabetes"                "mt_mat"                        
[137] "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                     
[141] "my_matrix2"                     "my_max"                        
[143] "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                        
[147] "my_vector"                      "mychar_d"                      
[149] "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                         
[153] "myvar_power"                    "n_15"                          
[155] "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                      
[159] "n_rep"                          "n_responders"                  
[161] "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                      
[165] "no_seed2"                       "non_norm_sample"               
[167] "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                   
[171] "norm_sample_density"            "norm_sample_ks_res"            
[173] "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                          
[177] "num2"                           "only_1"                        
[179] "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                   
[183] "patien2_sub"                    "patien3_sub"                   
[185] "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                      
[189] "patient2"                       "patient3"                      
[191] "pattern_to_check_1"             "pattern_to_check_2"            
[193] "perc_mito"                      "perc_no_mito"                  
[195] "pmi_thresh"                     "proteins"                      
[197] "proteins1"                      "proteins2"                     
[199] "PTPN7"                          "pvalue"                        
[201] "pvalue_to_plot"                 "quantiles"                     
[203] "r_numb"                         "r_patients"                    
[205] "read_sum_gene"                  "read_sum_pat"                  
[207] "read_sum_pat_filt"              "rep1"                          
[209] "rep2"                           "rep3"                          
[211] "response"                       "rin_area_boxplot"              
[213] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"       
[215] "rin_area_boxplots_arr"          "sample"                        
[217] "sample0"                        "sample1"                       
[219] "sample1_fr"                     "sample2"                       
[221] "sample2_fr"                     "sample3"                       
[223] "sample3_fr"                     "sd_calc"                       
[225] "sd_calc_ceil"                   "sd_calc_floor"                 
[227] "sd_calc_round"                  "sd_time"                       
[229] "sex"                            "sex_bar_arr"                   
[231] "sex_barplot"                    "sex_df"                        
[233] "sliced_odd"                     "sub_only"                      
[235] "sum_aa"                         "sum_tbl_sex"                   
[237] "sum_time"                       "sum_weights"                   
[239] "t_test_res"                     "t_value"                       
[241] "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[243] "t1_3_weight_df"                 "t1_3_weight_max"               
[245] "t1_3_weight_shapiro"            "Task3_bartlett_result"         
[247] "Task3_max_label"                "tbl_sex"                       
[249] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"      
[251] "tbl_sex_diagnosis_rowsum"       "time"                          
[253] "to_extract"                     "to_print"                      
[255] "to_remove"                      "total_mito"                    
[257] "total_no_mito"                  "treatment"                     
[259] "tukey_res"                      "untreated_chisq_res"           
[261] "untreated_cramer"               "untreated_df"                  
[263] "untreated_max_cat"              "untreated_mosaic"              
[265] "untreated_sample_size"          "untreated_table"               
[267] "untreated_weight_bartlett"      "untreated_weight_boxplot"      
[269] "untreated_weight_df"            "untreated_weight_lineplot"     
[271] "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"  
[273] "untreated_weight_stats_pos"     "upregulated_1"                 
[275] "upregulated_2"                  "var_calc"                      
[277] "var1"                           "var2"                          
[279] "var3"                           "weight"                        
[281] "weight_bartlett_result"         "weight_c"                      
[283] "weight_data"                    "weight_max_label"              
[285] "weight_n"                       "weight_sup_threshold"          
[287] "welch_res"                      "with_seed1"                    
[289] "with_seed2"                    
# delete just-created variable
rm(to_remove)

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                 
  [3] "age"                            "age_inf_threshold"             
  [5] "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                       
  [9] "aod_pmi_all"                    "aod_pmi_arr"                   
 [11] "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"             
 [15] "area_df"                        "areas"                         
 [17] "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                           
 [21] "ch3"                            "ch4"                           
 [23] "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                        
 [27] "common_all"                     "common_mean"                   
 [29] "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                  
 [33] "CXCR4"                          "description"                   
 [35] "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                   
 [39] "df_grouped"                     "df_male_ctrl_cdr4"             
 [41] "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                      
 [45] "dunn_res"                       "dunn_stat_df"                  
 [47] "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                   
 [51] "expr_mat_pat"                   "expr_values"                   
 [53] "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"         
 [57] "female_15_task1yes_expected"    "female_15_task1yes_max_cat"    
 [59] "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size"
 [63] "female_15_task1yes_table"       "female_t1_weight_bartlett"     
 [65] "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"      
 [69] "females_t1_task3_bartlett"      "females_t1_task3_boxplot"      
 [71] "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                     
 [75] "gene"                           "gene_2_keep"                   
 [77] "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                         
 [81] "grep_1"                         "grep_2"                        
 [83] "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                       
 [87] "idx"                            "interaction_factor"            
 [89] "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                           
 [93] "LHX9"                           "male_3_task2yes_df"            
 [95] "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"       
 [99] "male_3_task2yes_mosaic"         "male_3_task2yes_sample_size"   
[101] "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"               
[105] "male_3_task3_max"               "male_3_task3_shapiro"          
[107] "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"    
[111] "male_30_task3_qq"               "male_30_task3_qq_filt"         
[113] "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"   
[117] "male_30_weight_qq"              "male_30_weight_qq_filt"        
[119] "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                      
[123] "mean_col"                       "mean_res_better"               
[125] "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                     
[129] "mice1"                          "mice2"                         
[131] "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                     
[135] "mother_diabetes"                "mt_mat"                        
[137] "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                     
[141] "my_matrix2"                     "my_max"                        
[143] "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                        
[147] "my_vector"                      "mychar_d"                      
[149] "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                         
[153] "myvar_power"                    "n_15"                          
[155] "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                      
[159] "n_rep"                          "n_responders"                  
[161] "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                      
[165] "no_seed2"                       "non_norm_sample"               
[167] "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                   
[171] "norm_sample_density"            "norm_sample_ks_res"            
[173] "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                          
[177] "num2"                           "only_1"                        
[179] "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                   
[183] "patien2_sub"                    "patien3_sub"                   
[185] "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                      
[189] "patient2"                       "patient3"                      
[191] "pattern_to_check_1"             "pattern_to_check_2"            
[193] "perc_mito"                      "perc_no_mito"                  
[195] "pmi_thresh"                     "proteins"                      
[197] "proteins1"                      "proteins2"                     
[199] "PTPN7"                          "pvalue"                        
[201] "pvalue_to_plot"                 "quantiles"                     
[203] "r_numb"                         "r_patients"                    
[205] "read_sum_gene"                  "read_sum_pat"                  
[207] "read_sum_pat_filt"              "rep1"                          
[209] "rep2"                           "rep3"                          
[211] "response"                       "rin_area_boxplot"              
[213] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"       
[215] "rin_area_boxplots_arr"          "sample"                        
[217] "sample0"                        "sample1"                       
[219] "sample1_fr"                     "sample2"                       
[221] "sample2_fr"                     "sample3"                       
[223] "sample3_fr"                     "sd_calc"                       
[225] "sd_calc_ceil"                   "sd_calc_floor"                 
[227] "sd_calc_round"                  "sd_time"                       
[229] "sex"                            "sex_bar_arr"                   
[231] "sex_barplot"                    "sex_df"                        
[233] "sliced_odd"                     "sub_only"                      
[235] "sum_aa"                         "sum_tbl_sex"                   
[237] "sum_time"                       "sum_weights"                   
[239] "t_test_res"                     "t_value"                       
[241] "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[243] "t1_3_weight_df"                 "t1_3_weight_max"               
[245] "t1_3_weight_shapiro"            "Task3_bartlett_result"         
[247] "Task3_max_label"                "tbl_sex"                       
[249] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"      
[251] "tbl_sex_diagnosis_rowsum"       "time"                          
[253] "to_extract"                     "to_print"                      
[255] "total_mito"                     "total_no_mito"                 
[257] "treatment"                      "tukey_res"                     
[259] "untreated_chisq_res"            "untreated_cramer"              
[261] "untreated_df"                   "untreated_max_cat"             
[263] "untreated_mosaic"               "untreated_sample_size"         
[265] "untreated_table"                "untreated_weight_bartlett"     
[267] "untreated_weight_boxplot"       "untreated_weight_df"           
[269] "untreated_weight_lineplot"      "untreated_weight_shapiro"      
[271] "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[273] "upregulated_1"                  "upregulated_2"                 
[275] "var_calc"                       "var1"                          
[277] "var2"                           "var3"                          
[279] "weight"                         "weight_bartlett_result"        
[281] "weight_c"                       "weight_data"                   
[283] "weight_max_label"               "weight_n"                      
[285] "weight_sup_threshold"           "welch_res"                     
[287] "with_seed1"                     "with_seed2"                    

As we see, in the second case the to_remove variable has been removed.
What if I want to remove multiple variables? Let’s put multiple variable names inside the rm() function separated by commas:

# create various variables
to_remove <- 1213
to_remove2 <- 685

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                 
  [3] "age"                            "age_inf_threshold"             
  [5] "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                       
  [9] "aod_pmi_all"                    "aod_pmi_arr"                   
 [11] "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"             
 [15] "area_df"                        "areas"                         
 [17] "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                           
 [21] "ch3"                            "ch4"                           
 [23] "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                        
 [27] "common_all"                     "common_mean"                   
 [29] "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                  
 [33] "CXCR4"                          "description"                   
 [35] "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                   
 [39] "df_grouped"                     "df_male_ctrl_cdr4"             
 [41] "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                      
 [45] "dunn_res"                       "dunn_stat_df"                  
 [47] "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                   
 [51] "expr_mat_pat"                   "expr_values"                   
 [53] "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"         
 [57] "female_15_task1yes_expected"    "female_15_task1yes_max_cat"    
 [59] "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size"
 [63] "female_15_task1yes_table"       "female_t1_weight_bartlett"     
 [65] "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"      
 [69] "females_t1_task3_bartlett"      "females_t1_task3_boxplot"      
 [71] "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                     
 [75] "gene"                           "gene_2_keep"                   
 [77] "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                         
 [81] "grep_1"                         "grep_2"                        
 [83] "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                       
 [87] "idx"                            "interaction_factor"            
 [89] "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                           
 [93] "LHX9"                           "male_3_task2yes_df"            
 [95] "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"       
 [99] "male_3_task2yes_mosaic"         "male_3_task2yes_sample_size"   
[101] "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"               
[105] "male_3_task3_max"               "male_3_task3_shapiro"          
[107] "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"    
[111] "male_30_task3_qq"               "male_30_task3_qq_filt"         
[113] "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"   
[117] "male_30_weight_qq"              "male_30_weight_qq_filt"        
[119] "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                      
[123] "mean_col"                       "mean_res_better"               
[125] "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                     
[129] "mice1"                          "mice2"                         
[131] "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                     
[135] "mother_diabetes"                "mt_mat"                        
[137] "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                     
[141] "my_matrix2"                     "my_max"                        
[143] "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                        
[147] "my_vector"                      "mychar_d"                      
[149] "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                         
[153] "myvar_power"                    "n_15"                          
[155] "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                      
[159] "n_rep"                          "n_responders"                  
[161] "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                      
[165] "no_seed2"                       "non_norm_sample"               
[167] "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                   
[171] "norm_sample_density"            "norm_sample_ks_res"            
[173] "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                          
[177] "num2"                           "only_1"                        
[179] "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                   
[183] "patien2_sub"                    "patien3_sub"                   
[185] "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                      
[189] "patient2"                       "patient3"                      
[191] "pattern_to_check_1"             "pattern_to_check_2"            
[193] "perc_mito"                      "perc_no_mito"                  
[195] "pmi_thresh"                     "proteins"                      
[197] "proteins1"                      "proteins2"                     
[199] "PTPN7"                          "pvalue"                        
[201] "pvalue_to_plot"                 "quantiles"                     
[203] "r_numb"                         "r_patients"                    
[205] "read_sum_gene"                  "read_sum_pat"                  
[207] "read_sum_pat_filt"              "rep1"                          
[209] "rep2"                           "rep3"                          
[211] "response"                       "rin_area_boxplot"              
[213] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"       
[215] "rin_area_boxplots_arr"          "sample"                        
[217] "sample0"                        "sample1"                       
[219] "sample1_fr"                     "sample2"                       
[221] "sample2_fr"                     "sample3"                       
[223] "sample3_fr"                     "sd_calc"                       
[225] "sd_calc_ceil"                   "sd_calc_floor"                 
[227] "sd_calc_round"                  "sd_time"                       
[229] "sex"                            "sex_bar_arr"                   
[231] "sex_barplot"                    "sex_df"                        
[233] "sliced_odd"                     "sub_only"                      
[235] "sum_aa"                         "sum_tbl_sex"                   
[237] "sum_time"                       "sum_weights"                   
[239] "t_test_res"                     "t_value"                       
[241] "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[243] "t1_3_weight_df"                 "t1_3_weight_max"               
[245] "t1_3_weight_shapiro"            "Task3_bartlett_result"         
[247] "Task3_max_label"                "tbl_sex"                       
[249] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"      
[251] "tbl_sex_diagnosis_rowsum"       "time"                          
[253] "to_extract"                     "to_print"                      
[255] "to_remove"                      "to_remove2"                    
[257] "total_mito"                     "total_no_mito"                 
[259] "treatment"                      "tukey_res"                     
[261] "untreated_chisq_res"            "untreated_cramer"              
[263] "untreated_df"                   "untreated_max_cat"             
[265] "untreated_mosaic"               "untreated_sample_size"         
[267] "untreated_table"                "untreated_weight_bartlett"     
[269] "untreated_weight_boxplot"       "untreated_weight_df"           
[271] "untreated_weight_lineplot"      "untreated_weight_shapiro"      
[273] "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[275] "upregulated_1"                  "upregulated_2"                 
[277] "var_calc"                       "var1"                          
[279] "var2"                           "var3"                          
[281] "weight"                         "weight_bartlett_result"        
[283] "weight_c"                       "weight_data"                   
[285] "weight_max_label"               "weight_n"                      
[287] "weight_sup_threshold"           "welch_res"                     
[289] "with_seed1"                     "with_seed2"                    
# delete just-created variables
rm(to_remove, to_remove2)

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                 
  [3] "age"                            "age_inf_threshold"             
  [5] "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                       
  [9] "aod_pmi_all"                    "aod_pmi_arr"                   
 [11] "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"             
 [15] "area_df"                        "areas"                         
 [17] "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                           
 [21] "ch3"                            "ch4"                           
 [23] "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                        
 [27] "common_all"                     "common_mean"                   
 [29] "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                  
 [33] "CXCR4"                          "description"                   
 [35] "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                   
 [39] "df_grouped"                     "df_male_ctrl_cdr4"             
 [41] "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                      
 [45] "dunn_res"                       "dunn_stat_df"                  
 [47] "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                   
 [51] "expr_mat_pat"                   "expr_values"                   
 [53] "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"         
 [57] "female_15_task1yes_expected"    "female_15_task1yes_max_cat"    
 [59] "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size"
 [63] "female_15_task1yes_table"       "female_t1_weight_bartlett"     
 [65] "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"      
 [69] "females_t1_task3_bartlett"      "females_t1_task3_boxplot"      
 [71] "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                     
 [75] "gene"                           "gene_2_keep"                   
 [77] "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                         
 [81] "grep_1"                         "grep_2"                        
 [83] "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                       
 [87] "idx"                            "interaction_factor"            
 [89] "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                           
 [93] "LHX9"                           "male_3_task2yes_df"            
 [95] "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"       
 [99] "male_3_task2yes_mosaic"         "male_3_task2yes_sample_size"   
[101] "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"               
[105] "male_3_task3_max"               "male_3_task3_shapiro"          
[107] "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"    
[111] "male_30_task3_qq"               "male_30_task3_qq_filt"         
[113] "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"   
[117] "male_30_weight_qq"              "male_30_weight_qq_filt"        
[119] "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                      
[123] "mean_col"                       "mean_res_better"               
[125] "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                     
[129] "mice1"                          "mice2"                         
[131] "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                     
[135] "mother_diabetes"                "mt_mat"                        
[137] "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                     
[141] "my_matrix2"                     "my_max"                        
[143] "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                        
[147] "my_vector"                      "mychar_d"                      
[149] "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                         
[153] "myvar_power"                    "n_15"                          
[155] "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                      
[159] "n_rep"                          "n_responders"                  
[161] "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                      
[165] "no_seed2"                       "non_norm_sample"               
[167] "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                   
[171] "norm_sample_density"            "norm_sample_ks_res"            
[173] "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                          
[177] "num2"                           "only_1"                        
[179] "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                   
[183] "patien2_sub"                    "patien3_sub"                   
[185] "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                      
[189] "patient2"                       "patient3"                      
[191] "pattern_to_check_1"             "pattern_to_check_2"            
[193] "perc_mito"                      "perc_no_mito"                  
[195] "pmi_thresh"                     "proteins"                      
[197] "proteins1"                      "proteins2"                     
[199] "PTPN7"                          "pvalue"                        
[201] "pvalue_to_plot"                 "quantiles"                     
[203] "r_numb"                         "r_patients"                    
[205] "read_sum_gene"                  "read_sum_pat"                  
[207] "read_sum_pat_filt"              "rep1"                          
[209] "rep2"                           "rep3"                          
[211] "response"                       "rin_area_boxplot"              
[213] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"       
[215] "rin_area_boxplots_arr"          "sample"                        
[217] "sample0"                        "sample1"                       
[219] "sample1_fr"                     "sample2"                       
[221] "sample2_fr"                     "sample3"                       
[223] "sample3_fr"                     "sd_calc"                       
[225] "sd_calc_ceil"                   "sd_calc_floor"                 
[227] "sd_calc_round"                  "sd_time"                       
[229] "sex"                            "sex_bar_arr"                   
[231] "sex_barplot"                    "sex_df"                        
[233] "sliced_odd"                     "sub_only"                      
[235] "sum_aa"                         "sum_tbl_sex"                   
[237] "sum_time"                       "sum_weights"                   
[239] "t_test_res"                     "t_value"                       
[241] "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[243] "t1_3_weight_df"                 "t1_3_weight_max"               
[245] "t1_3_weight_shapiro"            "Task3_bartlett_result"         
[247] "Task3_max_label"                "tbl_sex"                       
[249] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"      
[251] "tbl_sex_diagnosis_rowsum"       "time"                          
[253] "to_extract"                     "to_print"                      
[255] "total_mito"                     "total_no_mito"                 
[257] "treatment"                      "tukey_res"                     
[259] "untreated_chisq_res"            "untreated_cramer"              
[261] "untreated_df"                   "untreated_max_cat"             
[263] "untreated_mosaic"               "untreated_sample_size"         
[265] "untreated_table"                "untreated_weight_bartlett"     
[267] "untreated_weight_boxplot"       "untreated_weight_df"           
[269] "untreated_weight_lineplot"      "untreated_weight_shapiro"      
[271] "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[273] "upregulated_1"                  "upregulated_2"                 
[275] "var_calc"                       "var1"                          
[277] "var2"                           "var3"                          
[279] "weight"                         "weight_bartlett_result"        
[281] "weight_c"                       "weight_data"                   
[283] "weight_max_label"               "weight_n"                      
[285] "weight_sup_threshold"           "welch_res"                     
[287] "with_seed1"                     "with_seed2"                    

The two variables have been removed.
But looking closely at these codes, we see that some start with # and are not evaluated. What are they? These are the comments, i.e. messages that you will write in the scripts (and we will see later how to create them) to help you understand what you are doing. They are actual comments that you can add, and will not be “evaluated” as code as the line starts with #.

Type of variables

So far so linear, right? Great, it will continue to be as easy 🙃.

Let’s see what are the basic types of variables that exist in R:

  • Numeric: numbers, can be integer (whole numbers) or double (decimal numbers)
  • Character: characters, therefore strings of letters (words, sentences, etc.)
  • Boolean: TRUE or FALSE, are a special type of variable that R interprets in its own way, but super super super useful
  • Factor: similar to character, but with peculiar features (and memory saving), often used for categorical variables such as male/female, heterozygous/wild-type

We will see each type of variable in detail in next chapters. To find out what type a variable is we use the typeof() function:

typeof(myvar)
[1] "double"

We see that myvar is a double (although it is an integer value), this is because R basically interprets every number as a double, so as to increase its precision and the possibility of operations between various numbers without having type problems.

Exercises

Ok, this chapter was long enough, let’s do some exercises to fix well these concepts.

Exercise 3.1 Create 3 variables indicating the weights of 3 mice.

Solution
mice1 <- 5.8
mice2 <- 4.8
mice3 <- 7.5

print(mice1)
[1] 5.8
print(mice2)
[1] 4.8
print(mice3)
[1] 7.5

Exercise 3.2 Create the variable sum_weights as the sum of the weights of those 3 mice.

Solution
sum_weights <- mice1 + mice2 + mice3
print(sum_weights)
[1] 18.1

Exercise 3.3 Create 4 other variables for other 4 mice that weight 20 g. Then you realize you did a mistake and you choose to delete 3 of them and change the fourth to 7.7.

Solution
# create 4 variables
mice4 <- mice5 <- mice6 <- mice7 <- 20

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                 
  [3] "age"                            "age_inf_threshold"             
  [5] "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                       
  [9] "aod_pmi_all"                    "aod_pmi_arr"                   
 [11] "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"             
 [15] "area_df"                        "areas"                         
 [17] "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                           
 [21] "ch3"                            "ch4"                           
 [23] "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                        
 [27] "common_all"                     "common_mean"                   
 [29] "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                  
 [33] "CXCR4"                          "description"                   
 [35] "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                   
 [39] "df_grouped"                     "df_male_ctrl_cdr4"             
 [41] "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                      
 [45] "dunn_res"                       "dunn_stat_df"                  
 [47] "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                   
 [51] "expr_mat_pat"                   "expr_values"                   
 [53] "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"         
 [57] "female_15_task1yes_expected"    "female_15_task1yes_max_cat"    
 [59] "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size"
 [63] "female_15_task1yes_table"       "female_t1_weight_bartlett"     
 [65] "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"      
 [69] "females_t1_task3_bartlett"      "females_t1_task3_boxplot"      
 [71] "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                     
 [75] "gene"                           "gene_2_keep"                   
 [77] "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                         
 [81] "grep_1"                         "grep_2"                        
 [83] "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                       
 [87] "idx"                            "interaction_factor"            
 [89] "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                           
 [93] "LHX9"                           "male_3_task2yes_df"            
 [95] "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"       
 [99] "male_3_task2yes_mosaic"         "male_3_task2yes_sample_size"   
[101] "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"               
[105] "male_3_task3_max"               "male_3_task3_shapiro"          
[107] "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"    
[111] "male_30_task3_qq"               "male_30_task3_qq_filt"         
[113] "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"   
[117] "male_30_weight_qq"              "male_30_weight_qq_filt"        
[119] "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                      
[123] "mean_col"                       "mean_res_better"               
[125] "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                     
[129] "mice1"                          "mice2"                         
[131] "mice3"                          "mice4"                         
[133] "mice5"                          "mice6"                         
[135] "mice7"                          "mito_genes"                    
[137] "ml_to_add"                      "mother_diabetes"               
[139] "mt_mat"                         "my_col_names"                  
[141] "my_df"                          "my_info"                       
[143] "my_matrix"                      "my_matrix2"                    
[145] "my_max"                         "my_mean"                       
[147] "my_min"                         "my_row_names"                  
[149] "my_sum"                         "my_vector"                     
[151] "mychar_d"                       "mychar_s"                      
[153] "mynumber"                       "mystring"                      
[155] "myvar"                          "myvar_power"                   
[157] "n_15"                           "n_3"                           
[159] "n_30"                           "n_7"                           
[161] "n_out_df"                       "n_rep"                         
[163] "n_responders"                   "n_t1"                          
[165] "n_untreated"                    "nationality"                   
[167] "no_seed1"                       "no_seed2"                      
[169] "non_norm_sample"                "non_norm_sample_density"       
[171] "non_norm_sample_ks_res"         "non_norm_sample_shapiro_res"   
[173] "norm_sample"                    "norm_sample_density"           
[175] "norm_sample_ks_res"             "norm_sample_shapiro_res"       
[177] "normality_df"                   "not_center"                    
[179] "num1"                           "num2"                          
[181] "only_1"                         "only_2"                        
[183] "p_responders"                   "pairwise_res"                  
[185] "patien1_sub"                    "patien2_sub"                   
[187] "patien3_sub"                    "patient_age"                   
[189] "patient_state"                  "patient_weight"                
[191] "patient1"                       "patient2"                      
[193] "patient3"                       "pattern_to_check_1"            
[195] "pattern_to_check_2"             "perc_mito"                     
[197] "perc_no_mito"                   "pmi_thresh"                    
[199] "proteins"                       "proteins1"                     
[201] "proteins2"                      "PTPN7"                         
[203] "pvalue"                         "pvalue_to_plot"                
[205] "quantiles"                      "r_numb"                        
[207] "r_patients"                     "read_sum_gene"                 
[209] "read_sum_pat"                   "read_sum_pat_filt"             
[211] "rep1"                           "rep2"                          
[213] "rep3"                           "response"                      
[215] "rin_area_boxplot"               "rin_area_boxplot_edit"         
[217] "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[219] "sample"                         "sample0"                       
[221] "sample1"                        "sample1_fr"                    
[223] "sample2"                        "sample2_fr"                    
[225] "sample3"                        "sample3_fr"                    
[227] "sd_calc"                        "sd_calc_ceil"                  
[229] "sd_calc_floor"                  "sd_calc_round"                 
[231] "sd_time"                        "sex"                           
[233] "sex_bar_arr"                    "sex_barplot"                   
[235] "sex_df"                         "sliced_odd"                    
[237] "sub_only"                       "sum_aa"                        
[239] "sum_tbl_sex"                    "sum_time"                      
[241] "sum_weights"                    "t_test_res"                    
[243] "t_value"                        "t1_3_weight_bartlett"          
[245] "t1_3_weight_boxplot"            "t1_3_weight_df"                
[247] "t1_3_weight_max"                "t1_3_weight_shapiro"           
[249] "Task3_bartlett_result"          "Task3_max_label"               
[251] "tbl_sex"                        "tbl_sex_diagnosis"             
[253] "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[255] "time"                           "to_extract"                    
[257] "to_print"                       "total_mito"                    
[259] "total_no_mito"                  "treatment"                     
[261] "tukey_res"                      "untreated_chisq_res"           
[263] "untreated_cramer"               "untreated_df"                  
[265] "untreated_max_cat"              "untreated_mosaic"              
[267] "untreated_sample_size"          "untreated_table"               
[269] "untreated_weight_bartlett"      "untreated_weight_boxplot"      
[271] "untreated_weight_df"            "untreated_weight_lineplot"     
[273] "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"  
[275] "untreated_weight_stats_pos"     "upregulated_1"                 
[277] "upregulated_2"                  "var_calc"                      
[279] "var1"                           "var2"                          
[281] "var3"                           "weight"                        
[283] "weight_bartlett_result"         "weight_c"                      
[285] "weight_data"                    "weight_max_label"              
[287] "weight_n"                       "weight_sup_threshold"          
[289] "welch_res"                      "with_seed1"                    
[291] "with_seed2"                    
# delete 3 of the just-created variables
rm(mice5, mice6, mice7)

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                 
  [3] "age"                            "age_inf_threshold"             
  [5] "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                       
  [9] "aod_pmi_all"                    "aod_pmi_arr"                   
 [11] "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"             
 [15] "area_df"                        "areas"                         
 [17] "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                           
 [21] "ch3"                            "ch4"                           
 [23] "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                        
 [27] "common_all"                     "common_mean"                   
 [29] "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                  
 [33] "CXCR4"                          "description"                   
 [35] "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                   
 [39] "df_grouped"                     "df_male_ctrl_cdr4"             
 [41] "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                      
 [45] "dunn_res"                       "dunn_stat_df"                  
 [47] "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                   
 [51] "expr_mat_pat"                   "expr_values"                   
 [53] "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"         
 [57] "female_15_task1yes_expected"    "female_15_task1yes_max_cat"    
 [59] "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size"
 [63] "female_15_task1yes_table"       "female_t1_weight_bartlett"     
 [65] "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"      
 [69] "females_t1_task3_bartlett"      "females_t1_task3_boxplot"      
 [71] "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                     
 [75] "gene"                           "gene_2_keep"                   
 [77] "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                         
 [81] "grep_1"                         "grep_2"                        
 [83] "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                       
 [87] "idx"                            "interaction_factor"            
 [89] "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                           
 [93] "LHX9"                           "male_3_task2yes_df"            
 [95] "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"       
 [99] "male_3_task2yes_mosaic"         "male_3_task2yes_sample_size"   
[101] "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"               
[105] "male_3_task3_max"               "male_3_task3_shapiro"          
[107] "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"    
[111] "male_30_task3_qq"               "male_30_task3_qq_filt"         
[113] "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"   
[117] "male_30_weight_qq"              "male_30_weight_qq_filt"        
[119] "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                      
[123] "mean_col"                       "mean_res_better"               
[125] "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                     
[129] "mice1"                          "mice2"                         
[131] "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                     
[135] "mother_diabetes"                "mt_mat"                        
[137] "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                     
[141] "my_matrix2"                     "my_max"                        
[143] "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                        
[147] "my_vector"                      "mychar_d"                      
[149] "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                         
[153] "myvar_power"                    "n_15"                          
[155] "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                      
[159] "n_rep"                          "n_responders"                  
[161] "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                      
[165] "no_seed2"                       "non_norm_sample"               
[167] "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                   
[171] "norm_sample_density"            "norm_sample_ks_res"            
[173] "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                          
[177] "num2"                           "only_1"                        
[179] "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                   
[183] "patien2_sub"                    "patien3_sub"                   
[185] "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                      
[189] "patient2"                       "patient3"                      
[191] "pattern_to_check_1"             "pattern_to_check_2"            
[193] "perc_mito"                      "perc_no_mito"                  
[195] "pmi_thresh"                     "proteins"                      
[197] "proteins1"                      "proteins2"                     
[199] "PTPN7"                          "pvalue"                        
[201] "pvalue_to_plot"                 "quantiles"                     
[203] "r_numb"                         "r_patients"                    
[205] "read_sum_gene"                  "read_sum_pat"                  
[207] "read_sum_pat_filt"              "rep1"                          
[209] "rep2"                           "rep3"                          
[211] "response"                       "rin_area_boxplot"              
[213] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"       
[215] "rin_area_boxplots_arr"          "sample"                        
[217] "sample0"                        "sample1"                       
[219] "sample1_fr"                     "sample2"                       
[221] "sample2_fr"                     "sample3"                       
[223] "sample3_fr"                     "sd_calc"                       
[225] "sd_calc_ceil"                   "sd_calc_floor"                 
[227] "sd_calc_round"                  "sd_time"                       
[229] "sex"                            "sex_bar_arr"                   
[231] "sex_barplot"                    "sex_df"                        
[233] "sliced_odd"                     "sub_only"                      
[235] "sum_aa"                         "sum_tbl_sex"                   
[237] "sum_time"                       "sum_weights"                   
[239] "t_test_res"                     "t_value"                       
[241] "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[243] "t1_3_weight_df"                 "t1_3_weight_max"               
[245] "t1_3_weight_shapiro"            "Task3_bartlett_result"         
[247] "Task3_max_label"                "tbl_sex"                       
[249] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"      
[251] "tbl_sex_diagnosis_rowsum"       "time"                          
[253] "to_extract"                     "to_print"                      
[255] "total_mito"                     "total_no_mito"                 
[257] "treatment"                      "tukey_res"                     
[259] "untreated_chisq_res"            "untreated_cramer"              
[261] "untreated_df"                   "untreated_max_cat"             
[263] "untreated_mosaic"               "untreated_sample_size"         
[265] "untreated_table"                "untreated_weight_bartlett"     
[267] "untreated_weight_boxplot"       "untreated_weight_df"           
[269] "untreated_weight_lineplot"      "untreated_weight_shapiro"      
[271] "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[273] "upregulated_1"                  "upregulated_2"                 
[275] "var_calc"                       "var1"                          
[277] "var2"                           "var3"                          
[279] "weight"                         "weight_bartlett_result"        
[281] "weight_c"                       "weight_data"                   
[283] "weight_max_label"               "weight_n"                      
[285] "weight_sup_threshold"           "welch_res"                     
[287] "with_seed1"                     "with_seed2"                    
# change the value of one variable
mice4 <- 7.7

print(mice4)
[1] 7.7

Alright, if you have done all the exercises (and I’m sure you have), we can move on to the next chapter in which we briefly talk about scripts and saving the environment.