Chapter 2 Interacting With RStudio
2.1 updates
R.version.string
checks 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.libPaths
lists where packages are saved in computer
2.4 import
2.4.1 csv
DF <- read.csv("FILENAME.csv", header = TRUE)
reads the.csv
file within the working directory- for files with multiple headers rows (often the case with
.csv
files from quatrics) use:DF <- read.csv("FILENAME", header = TRUE)[-1:-2,]
to import the.csv
without 2nd and 3rd rowswrite.csv(DF, "NEW_FILENAME.csv") # writes a new csv
to write a new.csv
on 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
<- read.csv("FILENAME", header = TRUE)[-1:-2,] # cleans the 2nd and 3rd
DF write.csv(DF, "FILENAME.csv") # writes a new csv
<- read.csv("FILENAME.csv", header = TRUE) # writes a new DF DF
2.4.2 excel
DF <- read.xlsx2("FILENAME.xlsx", 1)
requires thexlxs
package, reads the.xls
file 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)