Skip to content
Prev 389276 / 398506 Next

how to remove factors from whole dataframe?

Glad we have solutions BUT I note that the more abstract question is how to convert any columns that are factors to their base type and that may well NOT be character. They can be integers or doubles or complex or Boolean and maybe even raw. 

So undoing factorization may require using something like typeof() to get the base type and then depending on what final type you have, you may have to do things like as.integer(as.character(the_factor)) to get it as an integer and for a logical, as.logical(factor(c(TRUE, TRUE, FALSE, TRUE, FALSE))) and so on.

This seems like a fairly basic need so I wonder if anyone has already done it. I can see a fairly straightforward way to build a string and use eval and I suspect others might use something else like do.call() and yet others use multiple if statements or a case_when or something




-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Luigi Marongiu
Sent: Sunday, September 19, 2021 4:43 PM
To: Rui Barradas <ruipbarradas at sapo.pt>
Cc: r-help <r-help at r-project.org>
Subject: Re: [R] how to remove factors from whole dataframe?

Awesome, thanks!
On Sun, Sep 19, 2021 at 4:22 PM Rui Barradas <ruipbarradas at sapo.pt> wrote:
--
Best regards,
Luigi

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.