1

i am trying to make a loop for each columns in the database. i am getting this Error: Must use a vector in [, not an object of class matrix. my data looks like this: database str and this is my code:

for (q in 1:ncol(flat_file_numeric[])) {   
    qqnorm(flat_file_numeric[,q])
    qqline(flat_file_numeric[,q], col= "steelblue",lwd=2)}

i will appreciate any help. thanks.

Phil
  • 7,287
  • 3
  • 36
  • 66
  • 2
    Please include sample data in your question using `dput(df)`. – Vishal A. Feb 13 '22 at 11:35
  • 2
    Please don’t use images of data as they cannot be used without a lot of unnecessary effort. [For multiple reasons](//meta.stackoverflow.com/q/285551). Best if your question is [reproducible0](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Peter Feb 13 '22 at 11:40
  • movie_id budget popularity runtime revenue sw_web_presence sw_has_poster sw_tagline keyword_cnt sw_unknown_prod~ release_year release_month high_release_mo~ release_day years_of_war 1 5 0 1.15 118 3.92e6 1 1 1 0 1 2009 2 0 5 1 – Erez Kauffman Feb 13 '22 at 12:56

1 Answers1

0

Without some actual data is it hard to be sure, but from the error message it looks like some problem with the data itself.

I would start by trying this prior to the loop:

flat_file_numeric <- as.data.frame(flat_file_numeric)
Robert Long
  • 5,722
  • 5
  • 29
  • 50
  • 1
    Thanks @robert long it's actually worked. p.s- i tried to upload the data using dput or structure but It didn't work so i need to understand it better. – Erez Kauffman Feb 13 '22 at 16:42
  • You're welcome :) You should be able to just run `dput(flat_file_numeric)` (or just the first few rows if it is too large), then edit the original question and put the output in there. – Robert Long Feb 13 '22 at 17:22