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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:46:13+00:00 2026-05-26T08:46:13+00:00

I have very wide data frame and would like to create many short data

  • 0

I have very wide data frame and would like to create many short data frames? It looks like this:

location = c("A","B","C","D","E","F","G","H")                              
V1a = c(1,5,3,2,1,2,5,6)
V2a = c(3,2,6,7,3,2,1,2)
V3a = c(1,0,5,2,2,0,2,5)
V1b = c(3,2,6,7,3,2,1,2)
V2b = c(1,5,3,2,1,2,5,6)
V3b = c(1,5,3,2,1,2,5,6)
x <- data.frame(location,V1a,V2a,V3a,V1b,V2b,V3b)

x
  location V1a V2a V3a V1b V2b V3b
1        A   1   3   1   3   1   1
2        B   5   2   0   2   5   5
3        C   3   6   5   6   3   3
4        D   2   7   2   7   2   2
5        E   1   3   2   3   1   1
6        F   2   2   0   2   2   2
7        G   5   1   2   1   5   5
8        H   6   2   5   2   6   6

I would like to create from loop (if it is possible) 3 data frames as this

x1 <- x[,c(1,2,5)]
x1
  location V1a V1b
1        A   1   3
2        B   5   2
3        C   3   6
4        D   2   7
5        E   1   3
6        F   2   2
7        G   5   1
8        H   6   2

x2 <- x[,c(1,3,6)]
x2
  location V2a V2b
1        A   3   1
2        B   2   5
3        C   6   3
4        D   7   2
5        E   3   1
6        F   2   2
7        G   1   5
8        H   2   6

x3 <- x[,c(1,4,7)]
x3
  location V3a V3b
1        A   1   1
2        B   0   5
3        C   5   3
4        D   2   2
5        E   2   1
6        F   0   2
7        G   2   5
8        H   5   6

Thank you for your help!

  • 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-26T08:46:14+00:00Added an answer on May 26, 2026 at 8:46 am

    try this:

    idx <- list(c(1, 2, 5),
                c(1, 3, 6),
                c(1, 4, 7))
    
    ret <- lapply(idx, function(i) x[, i])
    

    ret is a list with 3 elements. You can access each element by ret[[1]] etc.
    If you really want to x1 etc, then,

    for (i in 1:length(ret)) assign(paste("x", i, sep = ""), ret[[i]])
    

    will do the work.

    But embedding index into the variable name is usually bad idea.

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

Sidebar

Related Questions

I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
Our application has a very large, wide table of transactional data. We have a
I currently have a very wide data view as a plain html table and
i have very simple problem. I need to create model, that represent element of
I have recently read about how cursors should be avoided. Well, I would like
I got very wide table of monthly indexes look like: index_id | ... |
This is a very wide-ranging/vague question, but here goes. Apologies in advance. The app
We have very strange problem, one of our applications is continually querying server by
I have very little experience building software for Windows, and zero experience using 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.