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

  • Home
  • SEARCH
  • 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 6048483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:28:05+00:00 2026-05-23T07:28:05+00:00

I need to paste, element by element, the contents of two data frames for

  • 0

I need to paste, element by element, the contents of two data frames for input to another program. I have a data frame of means and a data frame of standard errors of the mean.

I tried using the R paste() function, but it doesn’t seem to be able to cope with data frames. When using a vector, it seems to concatenate all the elements of the first vector into a string and all the elements of the second into a separate string. Instead, I need each reciprocal element in the two data frames to be concatenated together.

Any suggestions for how to approach this? I’ve included dummy input data (datMean and datSE) and my desired output (datNew). My real data frames are about 10 rows by 150 columns in size.

# means and SEM
datMean <- data.frame(a=rnorm(10, 3), b=rnorm(10, 3), d=rnorm(10, 3))
datSE <- data.frame(a=rnorm(10, 3)/100, b=rnorm(10, 3)/100, d=rnorm(10, 3)/100)

# what the output should look like
# i've chosen some arbitrary values here, and show only the first row. 
datNew <- data.frame(a="2.889-2.926", b="1.342-1.389", d="2.569-2.576")

The idea is for each element in datNew to be a range consisting of ‘mean – se’ and ‘mean + se’, separated by a dash ‘-‘ . The paste() function can do this for one element, how to do this over the whole dataframe?

paste(datMean[1,1] - datSE[1,1], datMean[1,1] + datSE[1,1], sep="-")

EDIT 1:
Looking at some of the answers I realize I left out an important bit of information in the question. Each row of the original data frames is named, and I need to reconstitute the final data frame with these names. For example:

rownames(datMean) <- LETTERS[1:10]
rownames(datSE) <- LETTERS[1:10]

I need datNew to eventually have these 10 rownames again. This could be problematic with some of the solutions using melt().

  • 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-05-23T07:28:06+00:00Added an answer on May 23, 2026 at 7:28 am

    If you convert to matrices first, you can do it with no applies or loops at all.

    MdatMean <- as.matrix(datMean)
    MdatSE <- as.matrix(datSE)
    matrix( paste(MdatMean - MdatSE, MdatMean + MdatSE, sep="-"), 
            nrow=nrow(MdatMean), dimnames=dimnames(MdatMean) )
    

    You also might consider formatC for better formatting.

    lo <- formatC(MdatMean - MdatSE, format="f", digits=3)
    hi <- formatC(MdatMean + MdatSE, format="f", digits=3)
    matrix( paste(lo, hi, sep="-"), 
            nrow=nrow(MdatMean), dimnames=dimnames(MdatMean) )
    

    If you want a data.frame in the end just wrap the last line in as.data.frame.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We need to stop copy paste of few characters like '<' or '>' or
need ask you about some help. I have web app running in Net 2.0.
Need some help about with Memcache. I have created a class and want to
I have a lot of data being placed into a <DIV> with the overflow:
I have pasted the example of what I need here : http://pastie.org/1005178 I have
I need a means of getting past Firefox's irritating refusal to pass the full
I have some HTML I need to parse. Basically I'm walking through the dom
I often* find myself in need of a data structure which has the following
In a library I am using I have the task of moving an element
I have two resources in my XAML which represent a Star and a Half

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.