Hi! I am trying to run a CFA in Rstudio.
Here are the commands I've ran (sorry, new users can apparently only add one picture to a post)
# load data
D <- read.csv("C:/Users/User/Downloads/results-survey278539.csv")
# make subset
dat <- D[,6:25]
# rename variables
names(dat) <- paste("Q", sep = "", 1:20)
# compute means
colMeans(dat)
model<-'f1=~Q1+Q2+Q3+Q4+Q5+Q6+Q7+Q8
f2=~Q9+Q10+Q11+Q12+Q13+Q14
f3=~Q15+Q16+Q17+Q18+Q19+Q20'
fit<-lavaan::cfa(model,data=dat)
fit<-cfa(model,data=D)
Summary(fit)But when I run the Summary(fit) I get the following error:
It might have something to do with the fact that the Lavaan package might not be properly installed, if I run install.packages("lavaan") I get the following pop-up:
'One or more of the packages that will be updated by this installation are currently loaded. Restarting R prior to updating these packages is strongly recommended. RStudio can restart R and then automatically continue the installation after restarting. Do you want to restart R prior to installing?
If I click Yes, nothing happens, the pop-up just reappears. If I click no, I get the following outcome:
> install.packages("lavaan")
Installing package into ‘U:/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/lavaan_0.6-5.zip'
Content type 'application/zip' length 2818039 bytes (2.7 MB)
downloaded 2.7 MB
package ‘lavaan’ successfully unpacked and MD5 sums checked
Error in install.packages : ERROR: failed to lock directory ‘U:\Documents\R\win-library\3.0’ for modifying
Try removing ‘U:\Documents\R\win-library\3.0/00LOCK’
If I run library(lavaan) nothing seems to be wrong.
I have just started using Rstudio so I have no idea how to fix this. Could someone help?