Skip to content

Write table with data in other .csv template

7 messages · Jeff Newmiller, s.s.m. fauzi

#
Thanks for posting dput data, but I don't understand your question.

are you familiar with cbind?
Is there duplication of column names in your input table and template? Are they always duplicated in the template? What characteristics of the template are you trying to preserve? Column order?

Other:
Don't post HTML email.
The name "table" is defined in the base package, so using it as a data name can lead to confusion and inability to perform fundamental operations.
---------------------------------------------------------------------------
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.
"s.s.m. fauzi" <ssmfone at gmail.com> wrote:

            
#
Perhaps you might try

template[ , names(tbl) ] <- tbl

where I have used tbl instead of table, for reasons previously mentioned.
---------------------------------------------------------------------------
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.
"s.s.m. fauzi" <ssmfone at gmail.com> wrote:

            
#
CSV files are on disk, with filenames. You can call them whatever you want, but they are not variables in R.

Data frames are variables in memory. You can read any CSV file into any data frame you like, but it replaces the original contents of the data frame completely. You can also write a data frame into a CSV file, but that always overwrites the entire file on disk. You may want to avoid writing over your input files, instead create a new output file.

You cannot manipulate CSV files in place using normal R programming techniques. You must load them into data frames, manipulate them, and write the result back to disk.

I used the name "template" because you did. You can use different names if you wish.

 I strongly recommend that you read "An Introduction to R" until you understand the syntax I used and can re-create it yourself using your own variables. Blindly using any code without understanding it is risky to your data.
---------------------------------------------------------------------------
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.
"s.s.m. fauzi" <ssmfone at gmail.com> wrote: