David Romano
2013-May-04 00:38 UTC
[R] how to best add columns to a matrix with many columns
Hi everyone, I have large data frame, say df1, with 165K columns, and all but the first four columns of df1 are numeric. I transformed the numeric data and obtained a matrix, call it data.m, with 165K - 4 columns, and then tried to create a second data frame by replacing the numeric columns of df1 by data.m. I did this in two ways, and both ways instantly used up all the available memory, so I was wondering whether there was a better way to do this. Here's what I tried: df2 <- df1 df2[ ,5:length(df1)] <- data.m and df2 <- cbind( df1[1:4], data.m) Thanks, David [[alternative HTML version deleted]]
Jeff Newmiller
2013-May-04 03:20 UTC
[R] how to best add columns to a matrix with many columns
I am not seeing any good justification in your description for converting to
matrix if you are planning to convert it back to data frame. Memory is going to
be inefficiently-used if you do this.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
David Romano <dromano at stanford.edu> wrote:
>Hi everyone,
>
>I have large data frame, say df1, with 165K columns, and all but the
>first
>four columns of df1 are numeric. I transformed the numeric data and
>obtained a matrix, call it data.m, with 165K - 4 columns, and then
>tried to
>create a second data frame by replacing the numeric columns of df1 by
>data.m. I did this in two ways, and both ways instantly used up all
>the
>available memory, so I was wondering whether there was a better way to
>do
>this.
>
>Here's what I tried:
>
>df2 <- df1
>df2[ ,5:length(df1)] <- data.m
>
>and
>
>df2 <- cbind( df1[1:4], data.m)
>
>Thanks,
>David
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>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.
Apparently Analagous Threads
- a newbie seeking for a simple problem
- how to compute when row length is different
- using ifelse to remove NA's from specific columns of a data frame containing strings and numbers
- Conditional operation on multiple columns from two data frames
- Replace columns in a data.frame randomly splitted