0

I have the following dataset :

MKT econ_unemp  econ_gas open
504 0.0743088   3.461    38
504 0.0740673   3.448    38
504 0.0740673   3.455    38
504 0.0740673   3.42     38
504 0.072682    3.391    38
505 0.0692244   3.345    38
505 0.0692244   3.381    38
505 0.0692244   3.484    38
505 0.0692244   3.488    38

I need to run factor analysis on the 3 variables by market so I used the split function in R to split the data:

  splitx<-split(data,data$DMA)

and then tried running factor analysis as follows:

for (i in 1:length(splitx)) {

 fa <- factanal(splitx[[i]],factors =1)
  }

But I am getting the following error:

Error in optim(start, FAfn, FAgr, method = "L-BFGS-B", lower = lower,:non-finite value supplied by optim

I hope the information provided is sufficient. Can someone help me fix this.

Regards

user6016731
  • 382
  • 5
  • 18
  • I think you wanted `factanal(splitx[[i]],factors =1)` otherwise you're not using `i` at all in the loop which would be silly. – MrFlick Mar 07 '16 at 05:26
  • Yes but doing so I get the following error: Error in optim(start, FAfn, FAgr, method = "L-BFGS-B", lower = lower, : non-finite value supplied by optim – user6016731 Mar 07 '16 at 05:34

1 Answers1

0
by(data[, -1], data[, 1], factanal, factors = 1)

That should do the trick, assuming MKT is the split variable.

Frank P.
  • 503
  • 5
  • 21