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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:22:09+00:00 2026-05-13T11:22:09+00:00

I’m trying to import some data into R and not having much luck grouping

  • 0

I’m trying to import some data into R and not having much luck grouping together rows of related data.

Example:
There a set of problems such as {A, B, C, D}. Each problem has two variables of interest which are being measured: “x” and “y”.
Each variable is analysed in terms of some simple statistics: min, max, mean, stddev.

So, my input data has the form:

      Min  Max  Mean  StdDev
A
  x   3    10   6.6   2.1 
  y   2    5    3.2   1.7
B
  x   3    10   6.6   2.1 
  y   2    5    3.2   1.7
C
  x   3    10   6.6   2.1 
  y   2    5    3.2   1.7
D
  x   3    10   6.6   2.1 
  y   2    5    3.2   1.7

Is there any way to preserve the structure of this data in R?
A similar problem is creating groups of columns (flip the table by 90 degrees to the right for example).

  • 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-13T11:22:10+00:00Added an answer on May 13, 2026 at 11:22 am

    You actually have many options: a data frame (relational table), or list. The following code will show how to create a data frame, and then to split it into a list containing the elements {x,y} or {A,B,C,D}:

    > txt <- "      Min  Max  Mean  StdDev
    + A
    +   x   3    10   6.6   2.1 
    +   y   2    5    3.2   1.7
    + B
    +   x   3    10   6.6   2.1 
    +   y   2    5    3.2   1.7
    + C
    +   x   3    10   6.6   2.1 
    +   y   2    5    3.2   1.7
    + D
    +   x   3    10   6.6   2.1 
    +   y   2    5    3.2   1.7
    + "
    > 
    > data <- head(readLines(textConnection(txt)),-1)
    > fields <- strsplit(sub("^[ ]+","",data[!nchar(data)==1]),"[ ]+")
    > DF <- `names<-`(data.frame(rep(data[nchar(data)==1],each=2), ## letters
    +                            do.call(rbind,fields[-1])),       ## data
    +                 c("Letter","xy",fields[[1]]))                ## colnames
    > split(DF,DF$xy)
    $x
      Letter xy Min Max Mean StdDev
    1      A  x   3  10  6.6    2.1
    3      B  x   3  10  6.6    2.1
    5      C  x   3  10  6.6    2.1
    7      D  x   3  10  6.6    2.1
    
    $y
      Letter xy Min Max Mean StdDev
    2      A  y   2   5  3.2    1.7
    4      B  y   2   5  3.2    1.7
    6      C  y   2   5  3.2    1.7
    8      D  y   2   5  3.2    1.7
    
    > split(DF,DF$Letter)
    $A
      Letter xy Min Max Mean StdDev
    1      A  x   3  10  6.6    2.1
    2      A  y   2   5  3.2    1.7
    
    $B
      Letter xy Min Max Mean StdDev
    3      B  x   3  10  6.6    2.1
    4      B  y   2   5  3.2    1.7
    
    $C
      Letter xy Min Max Mean StdDev
    5      C  x   3  10  6.6    2.1
    6      C  y   2   5  3.2    1.7
    
    $D
      Letter xy Min Max Mean StdDev
    7      D  x   3  10  6.6    2.1
    8      D  y   2   5  3.2    1.7
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.