I would like to change the format (class) of some columns of my data.frame object ( I don't want to do this when I'm reading the text file by Any help would be appreciated.
zx8754 48.9k11 gold badges114 silver badges192 bronze badges asked Feb 12, 2012 at 18:17
4 Hi welcome to the world of R.
This also works for character, dates, integers and other classes Since you're new to R I'd suggest you have a look at these two websites: R reference manuals: http://cran.r-project.org/manuals.html R Reference card: http://cran.r-project.org/doc/contrib/Short-refcard.pdf answered Feb 12, 2012 at 18:28
Tyler RinkerTyler Rinker 106k64 gold badges319 silver badges509 bronze badges 3
Explanation. All dataframes are lists and the results of Another strategy would be to convert only those columns where the number of unique items is less than some criterion, let's say fewer than the log of the number of rows as an example:
answered Feb 12, 2012 at 20:35
IRTFMIRTFM 256k20 gold badges361 silver badges483 bronze badges 3 You could use
answered Apr 10, 2018 at 12:06
sbhasbha 9,1482 gold badges69 silver badges60 bronze badges 1 If you want to change all character variables in your data.frame to factors after you've already loaded your data, you can do it like this, to a data.frame called
This creates a vector identifying which columns are of class Sample data:
answered Jan 7, 2016 at 21:59
Sam FirkeSam Firke 20.2k9 gold badges83 silver badges96 bronze badges 1 Another
short way you could use is a pipe (
answered Jun 24, 2016 at 8:12
chriadchriad 1,33215 silver badges22 bronze badges 2 I've doing it with a function. In this case I will only transform character variables to factor:
answered Jun 1, 2017 at 23:47
Edu MarínEdu Marín 891 silver badge5 bronze badges 1 Unless you need to identify the columns automatically, I found this to be the simplest solution:
This makes column answered Dec 25, 2020 at 20:16
Christian LindigChristian Lindig 1,1971 gold badge8 silver badges24 bronze badges
You can use
answered Jul 14, 2021 at 10:32
Ronak ShahRonak Shah 365k19 gold badges140 silver badges197 bronze badges |