mercredi 24 juin 2015

R: apply and nchar with if condition

I am trying to write a test for my data to print if there are any strings longer than 9 characters long in a column of a dataframe.

When using apply, I get confused as to how have it run nchar as a function with an if statement. I thought it would be something like this:

apply(df$a, 2, function(x) if nchar(x>9), nchar(x))

However I get an error: unexpected symbol in...

What am I missing here?

Aucun commentaire:

Enregistrer un commentaire