-2

I am trying to run a loop in columns and check field type.

for(i in names(SQLQUERYOUTPUT)){
  abc<- sapply(SQLQUERYOUTPUT[i], class)
  print(abc)  
  if is.numeric(abc)
  {
     min(SQLQUERYOUTPUT[i])
  }

  IF is.character(abc)
     max(nchar(SQLQUERYOUTPUT[i]))
  }  
}

if column is numeric then need lowest value and if its string then value with maximum length.

Its not working. Can anyone please help me on this

sunny k
  • 33
  • 2
  • 11
  • 1
    Please share a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Ronak Shah Dec 08 '16 at 17:57

1 Answers1

1

Your if-clauses are not correct. The function class will always return a string, e.g. "character" or "numeric". This means your if-clauses have to look like:

if(abc == "numeric"){...}
if(abc == "character"){...}
Felix Grossmann
  • 1,224
  • 1
  • 11
  • 30