Dear all, Unfortunately, we are unable to share an R script format file but you will find the exact content of the R script used in the webinar in this notepad. Please follow the instructions to use it in R: - Open R Studio - Open a new script: File... open file - Copy the content of this notepad and paste it onto the new script - save the script in R studio using: File... save as - Now you can use this script on R Studio Copy from here in R Studio --> #------------------------------------------ # UKDS NCRM Getting started with R webinar #----------------------------------------- ## set working directory (ideally where the data are saved) setwd("copy/the/Path/to/your/folder/here") # example in my PC: (it won't work in your PC because the path # is different) # setwd(C:/Users/Anita/UKDS/NCRM workshop") # Function to know your current working directory getwd() ## Installing packages (one time instalation) install.packages('tidyverse') install.packages('haven') install.packages("foreign") # Loading packages (load the packages in every session!) library(tidyverse) library(haven) library(foreign) ## Data types and structures # Creating variables (vectors) of lenght 1 a <- 3 b <- 5 c <- 9 # basic operaction with variables b*c #assigning the result to a new variable called 'd' d <- b*c/a ## Loading/Importing data into R # using the function read_csv of the package 'readr' (tidyverse) # for .csv files family <- read_csv("family_composition.csv") # or use the click option # checking data types and structure using the function 'class' class(family) class(family$age) class(family$sex) class(family$twinsis) # basic analysis # numeric variables. Central tendency measures summary(family$age) # standard deviation sd(family$age) # this won't work due to missing values # Now, making explicit that we want the missing values to be # removed using the function: 'na.rm = TRUE', as follow: sd(family$age, na.rm = TRUE) # Try with others variables! # character/ nominal variable. frequency table table(family$sex) # You can save this as a table (it will appear # in the global environment over there --->) freq <- table(family$sex) # now check the table (select 'freq' and press RUN) freq # You can also run crosstabulations (with proportions) using # the function 'table' and 'prop.table' as follow: prop.table(table(family$sex)) # if we want the result in percentages, use R as calculator and # multiply *100 prop.table(table(family$sex))*100