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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:36:57+00:00 2026-05-30T22:36:57+00:00

I have problem to convert a classic input data with reshape My input data

  • 0

I have problem to convert a classic input data with reshape

My input data :

   df <- read.table(textConnection(" Ville POP1999 POP2010 PARC1999 PARC2010
    1 Paris 1800000 2200000 150 253
    2 Itxassou 1000 1800 0 NA
    "))

with result in this data.frame :

     Ville   POP1999 POP2010 PARC1999 PARC2010
1    Paris 1800000 2200000    150      253
2 Itxassou    1000    1800      0       NA

I have this type of input, and i want to use colsplit (reshape2 package) with regex to cut my dataframe like this :

     Ville    Date    Population Parc 
1    Paris    1999    1800000    150
2    Paris    2010    2200000    253
3    Itxassou 1999    1000       0
4    Itxassou 2010    1800       NA

Do you think it’s possible to make this in one line with reshape 1 or 2 and colsplit function ?

My id equal “Ville” + “Date”, so i think it’s difficult to cut first with colsplit, and after that re-use the result id colum with meld :/

Do you have an idea of answer ?

Update 1 :

I add some difficulty to this problem, imagine now we have thousand of column, and column are mixed. I try to use grep and reshape, but no result at this time.. (see comments on @kohske great answer)

Update 2 :

@kohske resolve the problem with adding this code :

cn <- grep("*[0-9]",names(df),value="TRUE")
reshape(df, varying =  cn, direction = "long", 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-05-30T22:36:58+00:00Added an answer on May 30, 2026 at 10:36 pm

    you can use stats::reshape:

    > reshape(df, 2:5, direction = "long", sep = "")
              Ville time     POP PARC id
    1.1999    Paris 1999 1800000  150  1
    2.1999 Itxassou 1999    1000    0  2
    1.2010    Paris 2010 2200000  253  1
    2.2010 Itxassou 2010    1800   NA  2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using data.table: How do I convert column classes? Here is
I'm setting fields data via reflection. And I have a problem to convert string
have small problem, and would very much appreciate help :) I should convert byte
I have problem when I try insert some data to Informix TEXT column via
I have a problem in silverlight which I need to convert this image(from database
I have a problem with CFDataRef. I get the data field from a kCFSocketDataCallBack.
I have some problem convert C++ code to PHP. The purpose is I need
I have a problem when I convert an object to XML. The result is
I have a problem after I convert List<MyCustomObject> to a HashSet<MyCustomObject> . When I
I have problem. I can' identify my mistake... int dt = Convert.ToInt32(Items.Rows[T1][F14].ToString().Trim()); int mn

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.