class: title-slide <br> <br> .right-panel[ # Working with R ## Dr. Mine Dogucu ] --- ## Reminder - Close all apps on your computer. - Open slides for this session from the cluster website (https://cosmos-datascience.netlify.app). --- # Introductions --- # First things first: - Do you have a computer? - Do you have R on your computer? - Do you have RStudio on your computer? --- # A Walkthrough of RStudio ### Why it's a nice environment for R coding It is an IDE(Integrated Development Environment) which we use to manage and execute R code. It is open-source and free, and incoperated with other platforms. ### Create a new document in which to do R coding --- class: inverse middle center .font100[hello woRld] --- # R review ## Object assignment operator ``` r birth_year <- 2007 ``` --- # R review R is case-sensitive ``` r my_age <- 2024 - birth_year My_age ``` ``` ## Error in eval(expr, envir, enclos): object 'My_age' not found ``` --- ## Variables in R `character`: takes string values (e.g. a person's name, address) -- `integer`: integer (single precision) -- `double`: floating decimal (double precision) -- `numeric`: integer or double -- `factor`: categorical variables with different levels(AD, no AD) -- `logical`: TRUE (1), FALSE (0) --- ## Variables in R typeof is the function we use to check the type ``` r typeof(1) ``` ``` ## [1] "double" ``` ``` r typeof(1L) ``` ``` ## [1] "integer" ``` ``` r typeof(as.integer(1)) ``` ``` ## [1] "integer" ``` --- # R review If something comes in quotes, it is not defined in R. ``` r ages <- c(25, my_age, 32) names <- c("Menglin", "Mine", "Rafael") data.frame(age = ages, name = names) ``` ``` ## age name ## 1 25 Menglin ## 2 17 Mine ## 3 32 Rafael ``` --- # R review ## Functions and Arguments ``` r do(something) ``` `do()` is a function; `something` is the argument of the function. -- ``` r do(something, colorful) ``` `do()` is a function; `something` is the first argument of the function; `colorful` is the second argument of the function. --- # R review ## Getting Help In order to get any help we can use `?` followed by function (or object) name. ``` r ?c ``` --- # Some basic data structures - variables/assignment - combine/vector - matrix ``` r temp_variable = 1 temp_vector = c(1, 2, 3) temp_matrix = matrix(c(1,2,3,4), nrow=2, ncol=2, byrow=TRUE) ```