Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:29:13+00:00 2026-06-11T22:29:13+00:00

I have a table with data named dat , as below: Alison.Wong Bruno.Dumon Edward.J..Yoon

  • 0

I have a table with data named dat, as below:

               Alison.Wong Bruno.Dumon Edward.J..Yoon Eugene.Koontz Jakob.Homan
Alison Wong              0           0              0             1           1
Bruno Dumon              0           0              0             0           1
Edward J. Yoon           0           1              0             0           0
Eugene Koontz            0           0              0             0           1
Jakob Homan              1           0              1             0           0

dput(head(dat)

structure(list(Alison.Wong = c(0L, 0L, 0L, 0L, 1L), Bruno.Dumon = c(0L, 
0L, 1L, 0L, 0L), Edward.J..Yoon = c(0L, 0L, 0L, 0L, 1L), Eugene.Koontz = c(1L, 
0L, 0L, 0L, 0L), Jakob.Homan = c(1L, 1L, 0L, 1L, 0L)), .Names = c("Alison.Wong", 
"Bruno.Dumon", "Edward.J..Yoon", "Eugene.Koontz", "Jakob.Homan"
), row.names = c("Alison Wong", "Bruno Dumon", "Edward J. Yoon", 
"Eugene Koontz", "Jakob Homan"), class = "data.frame")

How can I combine the table above (which contains data) with other .csv template by preserving the order of the column in the template and also by preserving the data from the input file (dat), and save it with other name.

sample template file:

                Adrian.Cole Alison.Wong Andrei.Savu Bruno.Dumon Edward.J..Yoon
Adrian Cole               0           0           0           0              0
Alison Wong               0           0           0           0              0
Andrei Savu               0           0           0           0              0
Bruno Dumon               0           0           0           0              0
Edward J. Yoon            0           0           0           0              0
Eugene Koontz             0           0           0           0              0
Jakob Homan               0           0           0           0              0
Kelvin Kakugawa           0           0           0           0              0
                Eugene.Koontz Jakob.Homan Kelvin.Kakugawa
Adrian Cole                 0           0               0
Alison Wong                 0           0               0
Andrei Savu                 0           0               0
Bruno Dumon                 0           0               0
Edward J. Yoon              0           0               0
Eugene Koontz               0           0               0
Jakob Homan                 0           0               0
Kelvin Kakugawa             0           0               0

dput(head(template)):

structure(list(Adrian.Cole = c(0L, 0L, 0L, 0L, 0L, 0L), Alison.Wong = c(0L, 
0L, 0L, 0L, 0L, 0L), Andrei.Savu = c(0L, 0L, 0L, 0L, 0L, 0L), 
    Bruno.Dumon = c(0L, 0L, 0L, 0L, 0L, 0L), Edward.J..Yoon = c(0L, 
    0L, 0L, 0L, 0L, 0L), Eugene.Koontz = c(0L, 0L, 0L, 0L, 0L, 
    0L), Jakob.Homan = c(0L, 0L, 0L, 0L, 0L, 0L), Kelvin.Kakugawa = c(0L, 
    0L, 0L, 0L, 0L, 0L)), .Names = c("Adrian.Cole", "Alison.Wong", 
"Andrei.Savu", "Bruno.Dumon", "Edward.J..Yoon", "Eugene.Koontz", 
"Jakob.Homan", "Kelvin.Kakugawa"), row.names = c("Adrian Cole", 
"Alison Wong", "Andrei Savu", "Bruno Dumon", "Edward J. Yoon", 
"Eugene Koontz"), class = "data.frame")

sample output from this example:

                Adrian.Cole Alison.Wong Andrei.Savu Bruno.Dumon Edward.J..Yoon
Adrian Cole               0           0           0           0              0
Alison Wong               0           0           0           0              0
Andrei Savu               0           0           0           0              0
Bruno Dumon               0           0           0           0              0
Edward J. Yoon            0           0           0           1              0
Eugene Koontz             0           0           0           0              0
Jakob Homan               0           1           0           0              1
Kelvin Kakugawa           0           0           0           0              0
                Eugene.Koontz Jakob.Homan Kelvin.Kakugawa
Adrian Cole                 0           0               0
Alison Wong                 1           1               0
Andrei Savu                 0           0               0
Bruno Dumon                 0           1               0
Edward J. Yoon              0           0               0
Eugene Koontz               0           1               0
Jakob Homan                 0           0               0
Kelvin Kakugawa             0           0               0

I tried to use the following script, but it doesnt work.

template<- read.table("CR_template.csv", header=T, sep=",", row.names=1)
    template[match(rownames(cr), rownames(template)) , names(cr)] <- cr[ , names(cr)]
    result <- merge(cr, template)
    write.csv(result, paste("CR_FILES_", a.files[i], sep=""))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:29:14+00:00Added an answer on June 11, 2026 at 10:29 pm

    With the example you offered, it is incredibly easy:

    template[ , names(dat)] <- dat[ , names(dat)]
    

    However, what you posted as data does not match up with the (square) dimensions you are reporting for both ‘dat’ and ‘template’. So I would suggest you post a much smaller example for dat, say 5 x 5, and a slightly bigger example for ‘template’, say 8 x 8, and also post what you think the right answer should be.

    If there needs to be interleaving of both columns and rows then it’s possble something along these lines will succeed, but at the moment I consider it untested:

    template[match(rownames(dat), rownames(template)) , names(dat)] <- dat[ , names(dat)]
    

    For the edited version, this works:

    datrows <- match(rownames(template), rownames(dat) )
    transfer <- dat[ datrows[!is.na(datrows)], ]
    template[rownames(transfer) , colnames(transfer) ] <- transfer
    
    > template
                   Adrian.Cole Alison.Wong Andrei.Savu Bruno.Dumon Edward.J..Yoon Eugene.Koontz Jakob.Homan
    Adrian Cole              0           0           0           0              0             0           0
    Alison Wong              0           0           0           0              0             1           1
    Andrei Savu              0           0           0           0              0             0           0
    Bruno Dumon              0           0           0           0              0             0           1
    Edward J. Yoon           0           0           0           1              0             0           0
    Eugene Koontz            0           0           0           0              0             0           1
                   Kelvin.Kakugawa
    Adrian Cole                  0
    Alison Wong                  0
    Andrei Savu                  0
    Bruno Dumon                  0
    Edward J. Yoon               0
    Eugene Koontz                0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple database named customer with a single table data.I want to
I have these data from a table. Example, I have table for points named
I have a table named 'data' which stores the email addresses and city of
I have table in database named ads, this table contains data about each ad.
for example, i have a data table named [User], and mapping to User enetity
for example, i have a data table named [User], and mapping to User enetity
I have a data.table DT with a column named RF and many columns with
I have a table named tbl_course nad the data is like SID name DisplayOrder
I have a table named ServiceProviders with static data. The POCO class is follows
I have a table with a column named 'from'. I want to retrieve data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.