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"                  "age"                           
  [4] "age_inf_threshold"              "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                        "aod_pmi_all"                   
 [10] "aod_pmi_arr"                    "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"              "area_df"                       
 [16] "areas"                          "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                            "ch3"                           
 [22] "ch4"                            "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                         "common_all"                    
 [28] "common_mean"                    "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                   "CXCR4"                         
 [34] "description"                    "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                    "df_grouped"                    
 [40] "df_male_ctrl_cdr4"              "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                       "dunn_res"                      
 [46] "dunn_stat_df"                   "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                    "expr_mat_pat"                  
 [52] "expr_values"                    "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"          "female_15_task1yes_expected"   
 [58] "female_15_task1yes_max_cat"     "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size" "female_15_task1yes_table"      
 [64] "female_t1_weight_bartlett"      "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"       "females_t1_task3_bartlett"     
 [70] "females_t1_task3_boxplot"       "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                      "gene"                          
 [76] "gene_2_keep"                    "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                          "grep_1"                        
 [82] "grep_2"                         "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                        "idx"                           
 [88] "interaction_factor"             "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                            "LHX9"                          
 [94] "male_3_task2yes_df"             "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"        "male_3_task2yes_mosaic"        
[100] "male_3_task2yes_sample_size"    "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"                "male_3_task3_max"              
[106] "male_3_task3_shapiro"           "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"     "male_30_task3_qq"              
[112] "male_30_task3_qq_filt"          "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"    "male_30_weight_qq"             
[118] "male_30_weight_qq_filt"         "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                       "mean_col"                      
[124] "mean_res_better"                "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                      "mice1"                         
[130] "mice2"                          "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                      "mother_diabetes"               
[136] "mt_mat"                         "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                      "my_matrix2"                    
[142] "my_max"                         "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                         "my_vector"                     
[148] "mychar_d"                       "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                          "myvar_power"                   
[154] "n_15"                           "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                       "n_rep"                         
[160] "n_responders"                   "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                       "no_seed2"                      
[166] "non_norm_sample"                "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                    "norm_sample_density"           
[172] "norm_sample_ks_res"             "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                           "num2"                          
[178] "only_1"                         "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                    "patien2_sub"                   
[184] "patien3_sub"                    "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                       "patient2"                      
[190] "patient3"                       "pattern_to_check_1"             "pattern_to_check_2"            
[193] "pearson_res"                    "perc_mito"                      "perc_no_mito"                  
[196] "pmi_thresh"                     "proteins"                       "proteins1"                     
[199] "proteins2"                      "PTPN7"                          "pvalue"                        
[202] "pvalue_to_plot"                 "quantiles"                      "r_numb"                        
[205] "r_patients"                     "read_sum_gene"                  "read_sum_pat"                  
[208] "read_sum_pat_filt"              "rep1"                           "rep2"                          
[211] "rep3"                           "response"                       "rin_area_boxplot"              
[214] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[217] "sample"                         "sample0"                        "sample1"                       
[220] "sample1_fr"                     "sample2"                        "sample2_fr"                    
[223] "sample3"                        "sample3_fr"                     "sd_calc"                       
[226] "sd_calc_ceil"                   "sd_calc_floor"                  "sd_calc_round"                 
[229] "sd_time"                        "sex"                            "sex_bar_arr"                   
[232] "sex_barplot"                    "sex_df"                         "sliced_odd"                    
[235] "sub_only"                       "sum_aa"                         "sum_tbl_sex"                   
[238] "sum_time"                       "sum_weights"                    "t_test_res"                    
[241] "t_value"                        "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[244] "t1_3_weight_df"                 "t1_3_weight_max"                "t1_3_weight_shapiro"           
[247] "Task3_bartlett_result"          "Task3_max_label"                "tbl_sex"                       
[250] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[253] "time"                           "to_extract"                     "to_print"                      
[256] "total_mito"                     "total_no_mito"                  "treatment"                     
[259] "tukey_res"                      "untreated_chisq_res"            "untreated_cramer"              
[262] "untreated_df"                   "untreated_max_cat"              "untreated_mosaic"              
[265] "untreated_sample_size"          "untreated_table"                "untreated_weight_bartlett"     
[268] "untreated_weight_boxplot"       "untreated_weight_df"            "untreated_weight_lineplot"     
[271] "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[274] "upregulated_1"                  "upregulated_2"                  "var_calc"                      
[277] "var1"                           "var2"                           "var3"                          
[280] "weight"                         "weight_bartlett_result"         "weight_c"                      
[283] "weight_data"                    "weight_max_label"               "weight_n"                      
[286] "weight_sup_threshold"           "welch_res"                      "with_seed1"                    
[289] "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"                  "age"                           
  [4] "age_inf_threshold"              "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                        "aod_pmi_all"                   
 [10] "aod_pmi_arr"                    "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"              "area_df"                       
 [16] "areas"                          "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                            "ch3"                           
 [22] "ch4"                            "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                         "common_all"                    
 [28] "common_mean"                    "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                   "CXCR4"                         
 [34] "description"                    "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                    "df_grouped"                    
 [40] "df_male_ctrl_cdr4"              "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                       "dunn_res"                      
 [46] "dunn_stat_df"                   "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                    "expr_mat_pat"                  
 [52] "expr_values"                    "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"          "female_15_task1yes_expected"   
 [58] "female_15_task1yes_max_cat"     "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size" "female_15_task1yes_table"      
 [64] "female_t1_weight_bartlett"      "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"       "females_t1_task3_bartlett"     
 [70] "females_t1_task3_boxplot"       "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                      "gene"                          
 [76] "gene_2_keep"                    "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                          "grep_1"                        
 [82] "grep_2"                         "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                        "idx"                           
 [88] "interaction_factor"             "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                            "LHX9"                          
 [94] "male_3_task2yes_df"             "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"        "male_3_task2yes_mosaic"        
[100] "male_3_task2yes_sample_size"    "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"                "male_3_task3_max"              
[106] "male_3_task3_shapiro"           "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"     "male_30_task3_qq"              
[112] "male_30_task3_qq_filt"          "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"    "male_30_weight_qq"             
[118] "male_30_weight_qq_filt"         "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                       "mean_col"                      
[124] "mean_res_better"                "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                      "mice1"                         
[130] "mice2"                          "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                      "mother_diabetes"               
[136] "mt_mat"                         "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                      "my_matrix2"                    
[142] "my_max"                         "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                         "my_vector"                     
[148] "mychar_d"                       "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                          "myvar_power"                   
[154] "n_15"                           "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                       "n_rep"                         
[160] "n_responders"                   "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                       "no_seed2"                      
[166] "non_norm_sample"                "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                    "norm_sample_density"           
[172] "norm_sample_ks_res"             "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                           "num2"                          
[178] "only_1"                         "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                    "patien2_sub"                   
[184] "patien3_sub"                    "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                       "patient2"                      
[190] "patient3"                       "pattern_to_check_1"             "pattern_to_check_2"            
[193] "pearson_res"                    "perc_mito"                      "perc_no_mito"                  
[196] "pmi_thresh"                     "proteins"                       "proteins1"                     
[199] "proteins2"                      "PTPN7"                          "pvalue"                        
[202] "pvalue_to_plot"                 "quantiles"                      "r_numb"                        
[205] "r_patients"                     "read_sum_gene"                  "read_sum_pat"                  
[208] "read_sum_pat_filt"              "rep1"                           "rep2"                          
[211] "rep3"                           "response"                       "rin_area_boxplot"              
[214] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[217] "sample"                         "sample0"                        "sample1"                       
[220] "sample1_fr"                     "sample2"                        "sample2_fr"                    
[223] "sample3"                        "sample3_fr"                     "sd_calc"                       
[226] "sd_calc_ceil"                   "sd_calc_floor"                  "sd_calc_round"                 
[229] "sd_time"                        "sex"                            "sex_bar_arr"                   
[232] "sex_barplot"                    "sex_df"                         "sliced_odd"                    
[235] "sub_only"                       "sum_aa"                         "sum_tbl_sex"                   
[238] "sum_time"                       "sum_weights"                    "t_test_res"                    
[241] "t_value"                        "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[244] "t1_3_weight_df"                 "t1_3_weight_max"                "t1_3_weight_shapiro"           
[247] "Task3_bartlett_result"          "Task3_max_label"                "tbl_sex"                       
[250] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[253] "time"                           "to_extract"                     "to_print"                      
[256] "to_remove"                      "total_mito"                     "total_no_mito"                 
[259] "treatment"                      "tukey_res"                      "untreated_chisq_res"           
[262] "untreated_cramer"               "untreated_df"                   "untreated_max_cat"             
[265] "untreated_mosaic"               "untreated_sample_size"          "untreated_table"               
[268] "untreated_weight_bartlett"      "untreated_weight_boxplot"       "untreated_weight_df"           
[271] "untreated_weight_lineplot"      "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"  
[274] "untreated_weight_stats_pos"     "upregulated_1"                  "upregulated_2"                 
[277] "var_calc"                       "var1"                           "var2"                          
[280] "var3"                           "weight"                         "weight_bartlett_result"        
[283] "weight_c"                       "weight_data"                    "weight_max_label"              
[286] "weight_n"                       "weight_sup_threshold"           "welch_res"                     
[289] "with_seed1"                     "with_seed2"                    
# delete just-created variable
rm(to_remove)

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                  "age"                           
  [4] "age_inf_threshold"              "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                        "aod_pmi_all"                   
 [10] "aod_pmi_arr"                    "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"              "area_df"                       
 [16] "areas"                          "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                            "ch3"                           
 [22] "ch4"                            "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                         "common_all"                    
 [28] "common_mean"                    "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                   "CXCR4"                         
 [34] "description"                    "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                    "df_grouped"                    
 [40] "df_male_ctrl_cdr4"              "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                       "dunn_res"                      
 [46] "dunn_stat_df"                   "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                    "expr_mat_pat"                  
 [52] "expr_values"                    "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"          "female_15_task1yes_expected"   
 [58] "female_15_task1yes_max_cat"     "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size" "female_15_task1yes_table"      
 [64] "female_t1_weight_bartlett"      "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"       "females_t1_task3_bartlett"     
 [70] "females_t1_task3_boxplot"       "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                      "gene"                          
 [76] "gene_2_keep"                    "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                          "grep_1"                        
 [82] "grep_2"                         "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                        "idx"                           
 [88] "interaction_factor"             "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                            "LHX9"                          
 [94] "male_3_task2yes_df"             "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"        "male_3_task2yes_mosaic"        
[100] "male_3_task2yes_sample_size"    "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"                "male_3_task3_max"              
[106] "male_3_task3_shapiro"           "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"     "male_30_task3_qq"              
[112] "male_30_task3_qq_filt"          "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"    "male_30_weight_qq"             
[118] "male_30_weight_qq_filt"         "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                       "mean_col"                      
[124] "mean_res_better"                "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                      "mice1"                         
[130] "mice2"                          "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                      "mother_diabetes"               
[136] "mt_mat"                         "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                      "my_matrix2"                    
[142] "my_max"                         "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                         "my_vector"                     
[148] "mychar_d"                       "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                          "myvar_power"                   
[154] "n_15"                           "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                       "n_rep"                         
[160] "n_responders"                   "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                       "no_seed2"                      
[166] "non_norm_sample"                "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                    "norm_sample_density"           
[172] "norm_sample_ks_res"             "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                           "num2"                          
[178] "only_1"                         "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                    "patien2_sub"                   
[184] "patien3_sub"                    "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                       "patient2"                      
[190] "patient3"                       "pattern_to_check_1"             "pattern_to_check_2"            
[193] "pearson_res"                    "perc_mito"                      "perc_no_mito"                  
[196] "pmi_thresh"                     "proteins"                       "proteins1"                     
[199] "proteins2"                      "PTPN7"                          "pvalue"                        
[202] "pvalue_to_plot"                 "quantiles"                      "r_numb"                        
[205] "r_patients"                     "read_sum_gene"                  "read_sum_pat"                  
[208] "read_sum_pat_filt"              "rep1"                           "rep2"                          
[211] "rep3"                           "response"                       "rin_area_boxplot"              
[214] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[217] "sample"                         "sample0"                        "sample1"                       
[220] "sample1_fr"                     "sample2"                        "sample2_fr"                    
[223] "sample3"                        "sample3_fr"                     "sd_calc"                       
[226] "sd_calc_ceil"                   "sd_calc_floor"                  "sd_calc_round"                 
[229] "sd_time"                        "sex"                            "sex_bar_arr"                   
[232] "sex_barplot"                    "sex_df"                         "sliced_odd"                    
[235] "sub_only"                       "sum_aa"                         "sum_tbl_sex"                   
[238] "sum_time"                       "sum_weights"                    "t_test_res"                    
[241] "t_value"                        "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[244] "t1_3_weight_df"                 "t1_3_weight_max"                "t1_3_weight_shapiro"           
[247] "Task3_bartlett_result"          "Task3_max_label"                "tbl_sex"                       
[250] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[253] "time"                           "to_extract"                     "to_print"                      
[256] "total_mito"                     "total_no_mito"                  "treatment"                     
[259] "tukey_res"                      "untreated_chisq_res"            "untreated_cramer"              
[262] "untreated_df"                   "untreated_max_cat"              "untreated_mosaic"              
[265] "untreated_sample_size"          "untreated_table"                "untreated_weight_bartlett"     
[268] "untreated_weight_boxplot"       "untreated_weight_df"            "untreated_weight_lineplot"     
[271] "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[274] "upregulated_1"                  "upregulated_2"                  "var_calc"                      
[277] "var1"                           "var2"                           "var3"                          
[280] "weight"                         "weight_bartlett_result"         "weight_c"                      
[283] "weight_data"                    "weight_max_label"               "weight_n"                      
[286] "weight_sup_threshold"           "welch_res"                      "with_seed1"                    
[289] "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"                  "age"                           
  [4] "age_inf_threshold"              "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                        "aod_pmi_all"                   
 [10] "aod_pmi_arr"                    "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"              "area_df"                       
 [16] "areas"                          "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                            "ch3"                           
 [22] "ch4"                            "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                         "common_all"                    
 [28] "common_mean"                    "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                   "CXCR4"                         
 [34] "description"                    "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                    "df_grouped"                    
 [40] "df_male_ctrl_cdr4"              "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                       "dunn_res"                      
 [46] "dunn_stat_df"                   "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                    "expr_mat_pat"                  
 [52] "expr_values"                    "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"          "female_15_task1yes_expected"   
 [58] "female_15_task1yes_max_cat"     "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size" "female_15_task1yes_table"      
 [64] "female_t1_weight_bartlett"      "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"       "females_t1_task3_bartlett"     
 [70] "females_t1_task3_boxplot"       "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                      "gene"                          
 [76] "gene_2_keep"                    "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                          "grep_1"                        
 [82] "grep_2"                         "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                        "idx"                           
 [88] "interaction_factor"             "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                            "LHX9"                          
 [94] "male_3_task2yes_df"             "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"        "male_3_task2yes_mosaic"        
[100] "male_3_task2yes_sample_size"    "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"                "male_3_task3_max"              
[106] "male_3_task3_shapiro"           "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"     "male_30_task3_qq"              
[112] "male_30_task3_qq_filt"          "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"    "male_30_weight_qq"             
[118] "male_30_weight_qq_filt"         "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                       "mean_col"                      
[124] "mean_res_better"                "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                      "mice1"                         
[130] "mice2"                          "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                      "mother_diabetes"               
[136] "mt_mat"                         "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                      "my_matrix2"                    
[142] "my_max"                         "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                         "my_vector"                     
[148] "mychar_d"                       "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                          "myvar_power"                   
[154] "n_15"                           "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                       "n_rep"                         
[160] "n_responders"                   "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                       "no_seed2"                      
[166] "non_norm_sample"                "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                    "norm_sample_density"           
[172] "norm_sample_ks_res"             "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                           "num2"                          
[178] "only_1"                         "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                    "patien2_sub"                   
[184] "patien3_sub"                    "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                       "patient2"                      
[190] "patient3"                       "pattern_to_check_1"             "pattern_to_check_2"            
[193] "pearson_res"                    "perc_mito"                      "perc_no_mito"                  
[196] "pmi_thresh"                     "proteins"                       "proteins1"                     
[199] "proteins2"                      "PTPN7"                          "pvalue"                        
[202] "pvalue_to_plot"                 "quantiles"                      "r_numb"                        
[205] "r_patients"                     "read_sum_gene"                  "read_sum_pat"                  
[208] "read_sum_pat_filt"              "rep1"                           "rep2"                          
[211] "rep3"                           "response"                       "rin_area_boxplot"              
[214] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[217] "sample"                         "sample0"                        "sample1"                       
[220] "sample1_fr"                     "sample2"                        "sample2_fr"                    
[223] "sample3"                        "sample3_fr"                     "sd_calc"                       
[226] "sd_calc_ceil"                   "sd_calc_floor"                  "sd_calc_round"                 
[229] "sd_time"                        "sex"                            "sex_bar_arr"                   
[232] "sex_barplot"                    "sex_df"                         "sliced_odd"                    
[235] "sub_only"                       "sum_aa"                         "sum_tbl_sex"                   
[238] "sum_time"                       "sum_weights"                    "t_test_res"                    
[241] "t_value"                        "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[244] "t1_3_weight_df"                 "t1_3_weight_max"                "t1_3_weight_shapiro"           
[247] "Task3_bartlett_result"          "Task3_max_label"                "tbl_sex"                       
[250] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[253] "time"                           "to_extract"                     "to_print"                      
[256] "to_remove"                      "to_remove2"                     "total_mito"                    
[259] "total_no_mito"                  "treatment"                      "tukey_res"                     
[262] "untreated_chisq_res"            "untreated_cramer"               "untreated_df"                  
[265] "untreated_max_cat"              "untreated_mosaic"               "untreated_sample_size"         
[268] "untreated_table"                "untreated_weight_bartlett"      "untreated_weight_boxplot"      
[271] "untreated_weight_df"            "untreated_weight_lineplot"      "untreated_weight_shapiro"      
[274] "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"     "upregulated_1"                 
[277] "upregulated_2"                  "var_calc"                       "var1"                          
[280] "var2"                           "var3"                           "weight"                        
[283] "weight_bartlett_result"         "weight_c"                       "weight_data"                   
[286] "weight_max_label"               "weight_n"                       "weight_sup_threshold"          
[289] "welch_res"                      "with_seed1"                     "with_seed2"                    
# delete just-created variables
rm(to_remove, to_remove2)

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                  "age"                           
  [4] "age_inf_threshold"              "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                        "aod_pmi_all"                   
 [10] "aod_pmi_arr"                    "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"              "area_df"                       
 [16] "areas"                          "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                            "ch3"                           
 [22] "ch4"                            "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                         "common_all"                    
 [28] "common_mean"                    "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                   "CXCR4"                         
 [34] "description"                    "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                    "df_grouped"                    
 [40] "df_male_ctrl_cdr4"              "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                       "dunn_res"                      
 [46] "dunn_stat_df"                   "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                    "expr_mat_pat"                  
 [52] "expr_values"                    "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"          "female_15_task1yes_expected"   
 [58] "female_15_task1yes_max_cat"     "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size" "female_15_task1yes_table"      
 [64] "female_t1_weight_bartlett"      "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"       "females_t1_task3_bartlett"     
 [70] "females_t1_task3_boxplot"       "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                      "gene"                          
 [76] "gene_2_keep"                    "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                          "grep_1"                        
 [82] "grep_2"                         "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                        "idx"                           
 [88] "interaction_factor"             "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                            "LHX9"                          
 [94] "male_3_task2yes_df"             "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"        "male_3_task2yes_mosaic"        
[100] "male_3_task2yes_sample_size"    "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"                "male_3_task3_max"              
[106] "male_3_task3_shapiro"           "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"     "male_30_task3_qq"              
[112] "male_30_task3_qq_filt"          "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"    "male_30_weight_qq"             
[118] "male_30_weight_qq_filt"         "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                       "mean_col"                      
[124] "mean_res_better"                "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                      "mice1"                         
[130] "mice2"                          "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                      "mother_diabetes"               
[136] "mt_mat"                         "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                      "my_matrix2"                    
[142] "my_max"                         "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                         "my_vector"                     
[148] "mychar_d"                       "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                          "myvar_power"                   
[154] "n_15"                           "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                       "n_rep"                         
[160] "n_responders"                   "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                       "no_seed2"                      
[166] "non_norm_sample"                "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                    "norm_sample_density"           
[172] "norm_sample_ks_res"             "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                           "num2"                          
[178] "only_1"                         "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                    "patien2_sub"                   
[184] "patien3_sub"                    "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                       "patient2"                      
[190] "patient3"                       "pattern_to_check_1"             "pattern_to_check_2"            
[193] "pearson_res"                    "perc_mito"                      "perc_no_mito"                  
[196] "pmi_thresh"                     "proteins"                       "proteins1"                     
[199] "proteins2"                      "PTPN7"                          "pvalue"                        
[202] "pvalue_to_plot"                 "quantiles"                      "r_numb"                        
[205] "r_patients"                     "read_sum_gene"                  "read_sum_pat"                  
[208] "read_sum_pat_filt"              "rep1"                           "rep2"                          
[211] "rep3"                           "response"                       "rin_area_boxplot"              
[214] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[217] "sample"                         "sample0"                        "sample1"                       
[220] "sample1_fr"                     "sample2"                        "sample2_fr"                    
[223] "sample3"                        "sample3_fr"                     "sd_calc"                       
[226] "sd_calc_ceil"                   "sd_calc_floor"                  "sd_calc_round"                 
[229] "sd_time"                        "sex"                            "sex_bar_arr"                   
[232] "sex_barplot"                    "sex_df"                         "sliced_odd"                    
[235] "sub_only"                       "sum_aa"                         "sum_tbl_sex"                   
[238] "sum_time"                       "sum_weights"                    "t_test_res"                    
[241] "t_value"                        "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[244] "t1_3_weight_df"                 "t1_3_weight_max"                "t1_3_weight_shapiro"           
[247] "Task3_bartlett_result"          "Task3_max_label"                "tbl_sex"                       
[250] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[253] "time"                           "to_extract"                     "to_print"                      
[256] "total_mito"                     "total_no_mito"                  "treatment"                     
[259] "tukey_res"                      "untreated_chisq_res"            "untreated_cramer"              
[262] "untreated_df"                   "untreated_max_cat"              "untreated_mosaic"              
[265] "untreated_sample_size"          "untreated_table"                "untreated_weight_bartlett"     
[268] "untreated_weight_boxplot"       "untreated_weight_df"            "untreated_weight_lineplot"     
[271] "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[274] "upregulated_1"                  "upregulated_2"                  "var_calc"                      
[277] "var1"                           "var2"                           "var3"                          
[280] "weight"                         "weight_bartlett_result"         "weight_c"                      
[283] "weight_data"                    "weight_max_label"               "weight_n"                      
[286] "weight_sup_threshold"           "welch_res"                      "with_seed1"                    
[289] "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"                  "age"                           
  [4] "age_inf_threshold"              "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                        "aod_pmi_all"                   
 [10] "aod_pmi_arr"                    "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"              "area_df"                       
 [16] "areas"                          "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                            "ch3"                           
 [22] "ch4"                            "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                         "common_all"                    
 [28] "common_mean"                    "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                   "CXCR4"                         
 [34] "description"                    "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                    "df_grouped"                    
 [40] "df_male_ctrl_cdr4"              "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                       "dunn_res"                      
 [46] "dunn_stat_df"                   "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                    "expr_mat_pat"                  
 [52] "expr_values"                    "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"          "female_15_task1yes_expected"   
 [58] "female_15_task1yes_max_cat"     "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size" "female_15_task1yes_table"      
 [64] "female_t1_weight_bartlett"      "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"       "females_t1_task3_bartlett"     
 [70] "females_t1_task3_boxplot"       "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                      "gene"                          
 [76] "gene_2_keep"                    "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                          "grep_1"                        
 [82] "grep_2"                         "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                        "idx"                           
 [88] "interaction_factor"             "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                            "LHX9"                          
 [94] "male_3_task2yes_df"             "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"        "male_3_task2yes_mosaic"        
[100] "male_3_task2yes_sample_size"    "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"                "male_3_task3_max"              
[106] "male_3_task3_shapiro"           "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"     "male_30_task3_qq"              
[112] "male_30_task3_qq_filt"          "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"    "male_30_weight_qq"             
[118] "male_30_weight_qq_filt"         "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                       "mean_col"                      
[124] "mean_res_better"                "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                      "mice1"                         
[130] "mice2"                          "mice3"                          "mice4"                         
[133] "mice5"                          "mice6"                          "mice7"                         
[136] "mito_genes"                     "ml_to_add"                      "mother_diabetes"               
[139] "mt_mat"                         "my_col_names"                   "my_df"                         
[142] "my_info"                        "my_matrix"                      "my_matrix2"                    
[145] "my_max"                         "my_mean"                        "my_min"                        
[148] "my_row_names"                   "my_sum"                         "my_vector"                     
[151] "mychar_d"                       "mychar_s"                       "mynumber"                      
[154] "mystring"                       "myvar"                          "myvar_power"                   
[157] "n_15"                           "n_3"                            "n_30"                          
[160] "n_7"                            "n_out_df"                       "n_rep"                         
[163] "n_responders"                   "n_t1"                           "n_untreated"                   
[166] "nationality"                    "no_seed1"                       "no_seed2"                      
[169] "non_norm_sample"                "non_norm_sample_density"        "non_norm_sample_ks_res"        
[172] "non_norm_sample_shapiro_res"    "norm_sample"                    "norm_sample_density"           
[175] "norm_sample_ks_res"             "norm_sample_shapiro_res"        "normality_df"                  
[178] "not_center"                     "num1"                           "num2"                          
[181] "only_1"                         "only_2"                         "p_responders"                  
[184] "pairwise_res"                   "patien1_sub"                    "patien2_sub"                   
[187] "patien3_sub"                    "patient_age"                    "patient_state"                 
[190] "patient_weight"                 "patient1"                       "patient2"                      
[193] "patient3"                       "pattern_to_check_1"             "pattern_to_check_2"            
[196] "pearson_res"                    "perc_mito"                      "perc_no_mito"                  
[199] "pmi_thresh"                     "proteins"                       "proteins1"                     
[202] "proteins2"                      "PTPN7"                          "pvalue"                        
[205] "pvalue_to_plot"                 "quantiles"                      "r_numb"                        
[208] "r_patients"                     "read_sum_gene"                  "read_sum_pat"                  
[211] "read_sum_pat_filt"              "rep1"                           "rep2"                          
[214] "rep3"                           "response"                       "rin_area_boxplot"              
[217] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[220] "sample"                         "sample0"                        "sample1"                       
[223] "sample1_fr"                     "sample2"                        "sample2_fr"                    
[226] "sample3"                        "sample3_fr"                     "sd_calc"                       
[229] "sd_calc_ceil"                   "sd_calc_floor"                  "sd_calc_round"                 
[232] "sd_time"                        "sex"                            "sex_bar_arr"                   
[235] "sex_barplot"                    "sex_df"                         "sliced_odd"                    
[238] "sub_only"                       "sum_aa"                         "sum_tbl_sex"                   
[241] "sum_time"                       "sum_weights"                    "t_test_res"                    
[244] "t_value"                        "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[247] "t1_3_weight_df"                 "t1_3_weight_max"                "t1_3_weight_shapiro"           
[250] "Task3_bartlett_result"          "Task3_max_label"                "tbl_sex"                       
[253] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[256] "time"                           "to_extract"                     "to_print"                      
[259] "total_mito"                     "total_no_mito"                  "treatment"                     
[262] "tukey_res"                      "untreated_chisq_res"            "untreated_cramer"              
[265] "untreated_df"                   "untreated_max_cat"              "untreated_mosaic"              
[268] "untreated_sample_size"          "untreated_table"                "untreated_weight_bartlett"     
[271] "untreated_weight_boxplot"       "untreated_weight_df"            "untreated_weight_lineplot"     
[274] "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[277] "upregulated_1"                  "upregulated_2"                  "var_calc"                      
[280] "var1"                           "var2"                           "var3"                          
[283] "weight"                         "weight_bartlett_result"         "weight_c"                      
[286] "weight_data"                    "weight_max_label"               "weight_n"                      
[289] "weight_sup_threshold"           "welch_res"                      "with_seed1"                    
[292] "with_seed2"                    
# delete 3 of the just-created variables
rm(mice5, mice6, mice7)

# list all variables
ls()
  [1] "aa_num"                         "abbreviations"                  "age"                           
  [4] "age_inf_threshold"              "age_sup_threshold"              "all_plots"                     
  [7] "all_string"                     "aod_pmi"                        "aod_pmi_all"                   
 [10] "aod_pmi_arr"                    "aod_pmi_sex_rin_aes"            "aod_thresh"                    
 [13] "aov_res"                        "area_color_vector"              "area_df"                       
 [16] "areas"                          "c_patients"                     "caption"                       
 [19] "ch1"                            "ch2"                            "ch3"                           
 [22] "ch4"                            "ch5"                            "ch6"                           
 [25] "color_df"                       "common"                         "common_all"                    
 [28] "common_mean"                    "common1_2"                      "comparison_ks_res"             
 [31] "condition"                      "ctrl_sex_age"                   "CXCR4"                         
 [34] "description"                    "df"                             "df_AOD_dataset"                
 [37] "df_female_rin3q"                "df_filtered"                    "df_grouped"                    
 [40] "df_male_ctrl_cdr4"              "df_nas_diag_dataset"            "df_PMI_area_sex"               
 [43] "df_RIN_dataset"                 "df_wider"                       "dunn_res"                      
 [46] "dunn_stat_df"                   "expr"                           "expr_data"                     
 [49] "expr_data_t"                    "expr_levels"                    "expr_mat_pat"                  
 [52] "expr_values"                    "f_value"                        "features"                      
 [55] "female_15_task1yes_chisq_res"   "female_15_task1yes_df"          "female_15_task1yes_expected"   
 [58] "female_15_task1yes_max_cat"     "female_15_task1yes_mosaic"      "female_15_task1yes_or"         
 [61] "female_15_task1yes_phi"         "female_15_task1yes_sample_size" "female_15_task1yes_table"      
 [64] "female_t1_weight_bartlett"      "female_t1_weight_boxplot"       "female_t1_weight_df"           
 [67] "female_t1_weight_max"           "female_t1_weight_shapiro"       "females_t1_task3_bartlett"     
 [70] "females_t1_task3_boxplot"       "females_t1_task3_df"            "females_t1_task3_shapiro"      
 [73] "females_t1_task3_shapiro_pos"   "full_name"                      "gene"                          
 [76] "gene_2_keep"                    "gene_to_test"                   "gene1"                         
 [79] "gene2"                          "genes"                          "grep_1"                        
 [82] "grep_2"                         "grepl_1"                        "grepl_2"                       
 [85] "gsub_all"                       "heights"                        "idx"                           
 [88] "interaction_factor"             "is_odd"                         "is_outlier"                    
 [91] "kruskal_res"                    "LCT"                            "LHX9"                          
 [94] "male_3_task2yes_df"             "male_3_task2yes_expected"       "male_3_task2yes_fisher_phi"    
 [97] "male_3_task2yes_fisher_res"     "male_3_task2yes_max_cat"        "male_3_task2yes_mosaic"        
[100] "male_3_task2yes_sample_size"    "male_3_task2yes_table"          "male_3_task3_bartlett"         
[103] "male_3_task3_boxplot"           "male_3_task3_df"                "male_3_task3_max"              
[106] "male_3_task3_shapiro"           "male_30_task3_boxplot"          "male_30_task3_boxplot_filt"    
[109] "male_30_task3_density"          "male_30_task3_density_filt"     "male_30_task3_qq"              
[112] "male_30_task3_qq_filt"          "male_30_weight_boxplot"         "male_30_weight_boxplot_filt"   
[115] "male_30_weight_density"         "male_30_weight_density_filt"    "male_30_weight_qq"             
[118] "male_30_weight_qq_filt"         "male_30_weight_task3"           "males_data"                    
[121] "males_females_barplot"          "mann_res"                       "mean_col"                      
[124] "mean_res_better"                "mean_res_better_round"          "mean_result_calc"              
[127] "mean_row"                       "mean_time"                      "mice1"                         
[130] "mice2"                          "mice3"                          "mice4"                         
[133] "mito_genes"                     "ml_to_add"                      "mother_diabetes"               
[136] "mt_mat"                         "my_col_names"                   "my_df"                         
[139] "my_info"                        "my_matrix"                      "my_matrix2"                    
[142] "my_max"                         "my_mean"                        "my_min"                        
[145] "my_row_names"                   "my_sum"                         "my_vector"                     
[148] "mychar_d"                       "mychar_s"                       "mynumber"                      
[151] "mystring"                       "myvar"                          "myvar_power"                   
[154] "n_15"                           "n_3"                            "n_30"                          
[157] "n_7"                            "n_out_df"                       "n_rep"                         
[160] "n_responders"                   "n_t1"                           "n_untreated"                   
[163] "nationality"                    "no_seed1"                       "no_seed2"                      
[166] "non_norm_sample"                "non_norm_sample_density"        "non_norm_sample_ks_res"        
[169] "non_norm_sample_shapiro_res"    "norm_sample"                    "norm_sample_density"           
[172] "norm_sample_ks_res"             "norm_sample_shapiro_res"        "normality_df"                  
[175] "not_center"                     "num1"                           "num2"                          
[178] "only_1"                         "only_2"                         "p_responders"                  
[181] "pairwise_res"                   "patien1_sub"                    "patien2_sub"                   
[184] "patien3_sub"                    "patient_age"                    "patient_state"                 
[187] "patient_weight"                 "patient1"                       "patient2"                      
[190] "patient3"                       "pattern_to_check_1"             "pattern_to_check_2"            
[193] "pearson_res"                    "perc_mito"                      "perc_no_mito"                  
[196] "pmi_thresh"                     "proteins"                       "proteins1"                     
[199] "proteins2"                      "PTPN7"                          "pvalue"                        
[202] "pvalue_to_plot"                 "quantiles"                      "r_numb"                        
[205] "r_patients"                     "read_sum_gene"                  "read_sum_pat"                  
[208] "read_sum_pat_filt"              "rep1"                           "rep2"                          
[211] "rep3"                           "response"                       "rin_area_boxplot"              
[214] "rin_area_boxplot_edit"          "rin_area_boxplot_manual"        "rin_area_boxplots_arr"         
[217] "sample"                         "sample0"                        "sample1"                       
[220] "sample1_fr"                     "sample2"                        "sample2_fr"                    
[223] "sample3"                        "sample3_fr"                     "sd_calc"                       
[226] "sd_calc_ceil"                   "sd_calc_floor"                  "sd_calc_round"                 
[229] "sd_time"                        "sex"                            "sex_bar_arr"                   
[232] "sex_barplot"                    "sex_df"                         "sliced_odd"                    
[235] "sub_only"                       "sum_aa"                         "sum_tbl_sex"                   
[238] "sum_time"                       "sum_weights"                    "t_test_res"                    
[241] "t_value"                        "t1_3_weight_bartlett"           "t1_3_weight_boxplot"           
[244] "t1_3_weight_df"                 "t1_3_weight_max"                "t1_3_weight_shapiro"           
[247] "Task3_bartlett_result"          "Task3_max_label"                "tbl_sex"                       
[250] "tbl_sex_diagnosis"              "tbl_sex_diagnosis_colsum"       "tbl_sex_diagnosis_rowsum"      
[253] "time"                           "to_extract"                     "to_print"                      
[256] "total_mito"                     "total_no_mito"                  "treatment"                     
[259] "tukey_res"                      "untreated_chisq_res"            "untreated_cramer"              
[262] "untreated_df"                   "untreated_max_cat"              "untreated_mosaic"              
[265] "untreated_sample_size"          "untreated_table"                "untreated_weight_bartlett"     
[268] "untreated_weight_boxplot"       "untreated_weight_df"            "untreated_weight_lineplot"     
[271] "untreated_weight_shapiro"       "untreated_weight_shapiro_pos"   "untreated_weight_stats_pos"    
[274] "upregulated_1"                  "upregulated_2"                  "var_calc"                      
[277] "var1"                           "var2"                           "var3"                          
[280] "weight"                         "weight_bartlett_result"         "weight_c"                      
[283] "weight_data"                    "weight_max_label"               "weight_n"                      
[286] "weight_sup_threshold"           "welch_res"                      "with_seed1"                    
[289] "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.