Below is start-up code that will allow users to examine the 2021 Question 6 data using RStudio. ***Getting started*** Begin by copy-and-pasting the following text into the R-Studio prompt, which begins with > The code below will instruct RStudio where to locate the Question 6 data file, which R libraries to download and utilize, and how to interpret the Question 6 data. After the code is pasted into RStudio, *Do not hit enter yet*. Read the **Assigning the Pathway** section of this document first. #Copy and Paste everything beginning with this line #------------WORKING DIRECTORY------------ #The command below sets the r session to #work out of a specific folder. #Copy and paste the file path location #of your data into the quotations # next to filepath # (right click it in files # and look for the location). #Paste it inside the quotation marks. #BE SURE TO USE FORWARD SLASHES filepath = 'INPUT FILE LOCATION HERE' setwd(filepath) #------------INSTALL NECESSARY PACKAGES TO COMPUTER------------ if ("readxl" %in% installed.packages()[,1]){ print('readxl has already installed.') } else { install.packages('readxl') } if ("writexl" %in% installed.packages()[,1]){ print('writexl has already been installed.') } else { install.packages('writexl') } #------------BRING LIBRARIES INTO R SESSION------------ library(readxl) library(writexl) #------------BRING IN DATAFRAME------------ #Replace "DLC-COVID19WG-2021-biennial-survey-q6-2023.xlsx" with the actual name of the file #with the name of another xlsx file, if you would like to change #the data you want to work with. df <- read_xlsx('DLC-COVID19WG-2021-biennial-survey-q6-2023.xlsx') #assigns the xlsx to the variable df str(df) #shows what type of data each column is names = colnames(df) #to make life easier, use colnames and print them out so #you can copy and past the names when you subset. print(names) #------------SUBSET DATAFRAME------------ #subset a dataframe based on one column a = df[which((df$'Outreach Services' == 'X')),] #--------------------------------------- #subset a dataframe based on two columns #Libraries in either Virginia or Alabama who marked X for outreaches services. b = df[which((df$'State' %in% cbind('VA','AL')) & (df$'Outreach Services' == 'X')),] print(unique(df$'Library Size')) #Unique returns the unique values within a #column. You can copy and past a value you #want to subset for! #---------------------------------------- #subset a dataframe based on three columns #small library size and either staffing or reference services are X c = df[which((df$'Library Size' =='Small (less than 250,000 volumes in the library)') & (df$'Staffing' == 'X'| df$'Reference Services'=='X')),] print(unique(df$'Library Type')) #Library type is academic law and there were no new policies or procedures implements d = df[which((df$'Library Type' == 'Academic, Law Library (AL)') & (df$'No new policies or procedures implemented' == 'X')),] #Libraries that are selective type Regional #AND made changes to Collection maintenance and weeding #BUT did NOT make changes to the partnership agreement e = df[which(((df$'Depository Type'=='Selective') & (df$'Collection Maintenance and Weeding'=='X')) & ( (is.na(df$'Partnership Agreement'))| (df$'Partnership Agreement' =='Former'))),] #------------EXPORT DATAFRAME------------ #save your dataframe as an xlsx write_xlsx(c,'c.xlsx') #Stop Copy-and-Paste at this line. Do not hit Enter in RStudio yet. ***Assigning the Pathway*** Once the text above is copied into RStudio, go to line 11 filepath = 'INPUT FILE LOCATION HERE' The filepath is the file location on your computer and it tells RStudio where to locate the datafile. The name of the file itself already in the R code, so it will just need the location (eg. the folder/directory name). *For Mac Users: outside of RStudio, open the folder in which the Excel file is located. Look at the properties of the Excel file to see the directory path. The directory path is listed as “where” in the Mac properties box. In our example, it would look like /users/govinfouser/Desktop/Test. Copy and paste this into line 11 so the line reads: filepath= '/users/govinfouser/Desktop/Test' Once this is step is completed, hit Enter. This will load the Excel file into RStudio. The bottom left box will display the Excel data being unloading into RStudio. *For PC Users: outside of RStudio, open the folder in which the Excel file is located. Look at the properties of the file to see the directory path. The directory path is listed as “Location” in the PC properties box. In our example case, it would look like C:\Users\govinfouser\Desktop\Test Copy and paste this into line 14 so the command reads: filepath= 'C:/Users/govinfouser/Desktop/Test' Important Note: You will need to manually change the backslashes ( \ ) to forward slashes ( / ). Once this is step is completed, hit Enter. This will load the Excel file into RStudio. The bottom left box will display the Excel data being loading into RStudio. **Using RStudio** For detailed instructions on using Rstudio after the code is successfully introduced, see Appendix IV of the 2023 Working Group Report.