5.6 Load data into RStudio
Follow the steps below to load the data into RStudio.
- Launch RStudio software
- Navigate to
File > New File > R Script
to create an R Script.
- Save your new R script in the same folder as your extracted data set.
- You will need the following package for the analysis. Install/Load packages
# Install these packages if they are not installed
# install.packages("foreign")
# install.packages("psych")
library(GPArotation) # package for factor analysis
library(foreign) # load spss data
library(psych)
- Set working directory. Working directory literally means the location of any files you read into R or save out of R. This can be done by:
Session > Set Working Directory > Choose Directory
. Click onchoose directory
and navigate to the folder you saved the R script and extracted data. Then selectOpen
. - Use the below code to load data into RStudio. The data has 519,334 participants/observations and 921 variables/columns. We will preview the first six rows and eight columns only.
# Load data into RStudio
data <- read.spss("CY6_MS_CMB_STU_QQQ.sav",
to.data.frame = T, use.value.labels = F)
# Preview the first six rows and columns
head(data[ , c(1:8)])
## CNTRYID CNT CNTSCHID CNTSTUID CYC NatCen Region
## 1 8 ALB 800001 803627 06MS 000800 800
## 2 8 ALB 800001 800454 06MS 000800 800
## 3 8 ALB 800001 800893 06MS 000800 800
## 4 8 ALB 800001 804180 06MS 000800 800
## 5 8 ALB 800001 800491 06MS 000800 800
## 6 8 ALB 800001 804249 06MS 000800 800
## STRATUM
## 1 ALB0005
## 2 ALB0005
## 3 ALB0005
## 4 ALB0005
## 5 ALB0005
## 6 ALB0005