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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:53:11+00:00 2026-06-17T01:53:11+00:00

*Editing in response to comments I have a dataset that I am trying to

  • 0

*Editing in response to comments

I have a dataset that I am trying to prepare for analysis:

raw<-data.frame(
  name=c("Place 1", "Place 2", "Place 3", "Place 4"),
  x.1.Jan.12=c(1, NA, 0.5, NA),
  Jan.time=c("0900", NA, "0930", NA),
  x.15.Jan.12=c(NA, 0.7, NA, NA),
  Jan.time=c(NA, "1030", NA, NA),
  x.3.Feb.12=c(0.8, 0.6, 0.4, NA),
  Feb.time=c("0715", "0800", "0830", NA),
  x.8.Feb.12=c(NA, NA, 0.65, 0.33),
  Feb.time=c(NA, NA, "?", "1123")
  )

The data should be quite straightforward: a location with a result, a date for the result and the time it was collected. As you’ll see, date has been used to name the variable containing the result. Each ‘time’ variable relates to the column before it – the first ‘Jan.time’ variable is the time of the results in ‘x.1.Jan.12’

I want to restructure the data into four variables – name, date, time and value.
I’m pretty sure reshape2 can do it and have got the data melted:

mDat<-melt(raw, id=c("name"))

Can’t work out the next steps – probably to do with the wierd variable names.

The result I’d like is along these lines:

outData<-data.frame(
  name=c("Place 1", "Place 2", "Place 3", "Place 4", "Place 1", "Place 2", "Place 3", "Place 4", "Place 1", "Place 2", "Place 3", "Place 4", "Place 1", "Place 2", "Place 3", "Place 4"),
  date=c("1-Jan-12", "1-Jan-12", "1-Jan-12", "1-Jan-12", "15-Jan-12", "15-Jan-12", "15-Jan-12", "15-Jan-12", "3-Feb-12", "3-Feb-12", "3-Feb-12", "3-Feb-12", "8-Feb-12", "8-Feb-12", "8-Feb-12", "8-Feb-12"),
  value=c(1, NA, 0.5, NA, NA, 0.7, NA, NA, 0.8, 0.6, 0.4, NA, NA, NA, 0.65, 0.33),
  time=c("0900", NA, "0930", NA, NA, "1030", NA, NA, "0715", "0800", "0830", NA, NA, NA, "?", "1123")
)
  • 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-06-17T01:53:13+00:00Added an answer on June 17, 2026 at 1:53 am

    One option is to use melt() from “reshape2” on different subsets of your data.frame. The subsets can be extracted using grep().

    library(reshape2)
    temp <- cbind(
        setNames(melt(raw[c(1, grep("time", names(raw)))], id.vars="name"), 
                 c("name", "mon.time", "time")),
        setNames(melt(raw[grep("time", names(raw), invert = TRUE)], id.vars="name"),
                 c("name", "date", "result")))
    temp[, c("name", "result", "time", "date")]
    #       name result time        date
    # 1  Place 1   1.00 0900  x.1.Jan.12
    # 2  Place 2     NA <NA>  x.1.Jan.12
    # 3  Place 3   0.50 0930  x.1.Jan.12
    # 4  Place 4     NA <NA>  x.1.Jan.12
    # 5  Place 1     NA <NA> x.15.Jan.12
    # 6  Place 2   0.70 1030 x.15.Jan.12
    # 7  Place 3     NA <NA> x.15.Jan.12
    # 8  Place 4     NA <NA> x.15.Jan.12
    # 9  Place 1   0.80 0715  x.3.Feb.12
    # 10 Place 2   0.60 0800  x.3.Feb.12
    # 11 Place 3   0.40 0830  x.3.Feb.12
    # 12 Place 4     NA <NA>  x.3.Feb.12
    # 13 Place 1     NA <NA>  x.8.Feb.12
    # 14 Place 2     NA <NA>  x.8.Feb.12
    # 15 Place 3   0.65    ?  x.8.Feb.12
    # 16 Place 4   0.33 1123  x.8.Feb.12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have the inline editing in the raw data JSON response?
I am trying to use this library that allows for inline table editing, and
I have a form for editing notifications that looks like: <form action='edit.php' method =
I have a JQGrid that has the custom setup fro editing and saving row
I have a data entry and editing form and in every data entry or
On JBoss 4.2.3.GA, we have a JSP response that is being generated with transfer-encoding:chunked.
When editing data in a JTable (Nimbus L & F), as the user tabs
When editing a resource in the Visual Studio resource view, I find that a
The RFC seems to suggest that the client should permanently cache the response: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
jQgrid row is edited using inline editing mode. Pressing Enter sends data to server

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.