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 6863947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:51:00+00:00 2026-05-27T02:51:00+00:00

I am trying to use the structure() function to create a data frame in

  • 0

I am trying to use the structure() function to create a data frame in R.
I saw something like this

structure(mydataframe, class="data.frame")

Where did class come from? I saw someone using it, but it is not listed in the R document.

Is this something programmers learned in another language and carries it over? And it works. I am very confused.

Edit: I realized dput(), is what actually created a data frame looking like this. I got it figured out, cheers!

  • 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-27T02:51:01+00:00Added an answer on May 27, 2026 at 2:51 am

    You probably saw someone using dput. dput is used to post (usually short) data. But normally you would not create a data frame like that. You would normally create it with the data.frame function. See below

    > example_df <- data.frame(x=rnorm(3),y=rnorm(3))
    > example_df
               x          y
    1  0.2411880  0.6660809
    2 -0.5222567 -0.2512656
    3  0.3824853 -1.8420050
    > dput(example_df)
    structure(list(x = c(0.241188014013708, -0.522256746461544, 0.382485333260912
    ), y = c(0.666080872170054, -0.251265630627216, -1.84200501106852
    )), .Names = c("x", "y"), row.names = c(NA, -3L), class = "data.frame")
    

    Then, if someone wants to “copy” your data.frame, he just has to run the following:

    > copied_df <- structure(list(x = c(0.241188014013708, -0.522256746461544, 0.382485333260912
    +     ), y = c(0.666080872170054, -0.251265630627216, -1.84200501106852
    +     )), .Names = c("x", "y"), row.names = c(NA, -3L), class = "data.frame")
    

    I put “copy” in quotes because note the following:

    > identical(example_df,copied_df)
    [1] FALSE
    > all.equal(example_df,copied_df)
    [1] TRUE
    

    identical yields false because when you post your dput output, often the numbers get rounded to a certain decimal point.

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

Sidebar

Related Questions

I am trying to come up with the best data structure for use in
Using C++, I'm trying to create a generic container class to handle multiple data
I am trying to use use the following JSON data to create the following
I am creating a menu system using a UL/LI structure. I'm trying to use
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Basically, I know how to create graph data structures and use Dijkstra's algorithm in
I'm trying to create a table class, who's rows and columns may expand or
I am trying to play around with C data structure (hash table). I am
I am trying to use some pinvoke code to call a C function. The

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.