Chapter 2 Interacting With RStudio
2.1 updates
R.version.stringchecks for r version
2.2 working directory
setwd("~/WORKING_DIRECTORY_PATH")to load and save documents
2.3 packages
install.packages("PACKAGE")installs new package (required once)library(LIBRARY_NAME)attaches (opens) a package (required every time a session opened)search()lists packages currently attached.libPathslists where packages are saved in computer
2.4 import
2.4.1 csv
DF <- read.csv("FILENAME.csv", header = TRUE)reads the.csvfile within the working directory- for files with multiple headers rows (often the case with
.csvfiles from quatrics) use:DF <- read.csv("FILENAME", header = TRUE)[-1:-2,]to import the.csvwithout 2nd and 3rd rowswrite.csv(DF, "NEW_FILENAME.csv") # writes a new csvto write a new.csvon the working directoryDF <- read.csv("NEW_FILENAME.csv", header = TRUE)to import the new.csv- note that the file actions take place within the working directory, follows the code chunk
DF <- read.csv("FILENAME", header = TRUE)[-1:-2,] # cleans the 2nd and 3rd
write.csv(DF, "FILENAME.csv") # writes a new csv
DF <- read.csv("FILENAME.csv", header = TRUE) # writes a new DF2.4.2 excel
DF <- read.xlsx2("FILENAME.xlsx", 1)requires thexlxspackage, reads the.xlsfile within the working directory
2.4.3 SPSS
DF <- spss.get("FILENAME.sav", use.value.labels=TRUE) requires the Hmisc package, reads the .sav file within the working directory
2.5 objects in the environment
ls()to list all objects
rm(OBJECT)to remove an object (for several objects separete each object name by a coma)