[R] Simple loop problem

Yahya Laraki larakiyahya at gmail.com
Mon Oct 31 15:44:37 CET 2016


Hi everybody,

I’m new to R and i’m trying to learn fundamentals. I’m facing a small problem for which i can’t find a solution online.

What i want to do: write a function to lower case for all the columns in my data.frame if they respect a condition (class = factor)

This code works, but for all my columns : change_lower = function(x) {data.frame(tolower(as.matrix(x)))}

I need more something like this, but it doesn’t work: function (x) { for (i in 1:length(x)) {
  if (class(i)=="factor") {
    data.frame(tolower(as.matrix(x))) 
  }
}}

Thank you 

Yahya


More information about the R-help mailing list