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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:36:21+00:00 2026-06-12T17:36:21+00:00

Given the following data format, If D1 is a matrix in R how would

  • 0

Given the following data format, If D1 is a matrix in R how would I populate column X2 each day with a single, random 1 between the times of 0630 & 1030 (inclusive)?? Only one 1 per day, that 1 appearing at a random point. The real data is much longer, maybe 1000 days or more so I’d end up with 1000 1’s all placed between 0630 & 1030.

Note that while this is 5 minute data I’d like to find a solution that worked with other periods also. (15 minute, 1 minute, etc.) That could be a second step if necessary.

D1 <- structure(c(1110920, 1110920, 1110920, 1110920, 1110920, 1110920, 
1110920, 1110920, 1110920, 1110920, 1110920, 1110920, 1110920, 
1110920, 1110920, 1110920, 1110920, 1110920, 1110920, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 1110921, 
1110921, 1110921, 1110921, 1110921, 1110921, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 1110922, 
1110922, 1110922, 1110922, 1110922, 2225, 2230, 2235, 2240, 2245, 
2250, 2255, 2300, 2305, 2310, 2315, 2320, 2325, 2330, 2335, 2340, 
2345, 2350, 2355, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 
100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 200, 
205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 300, 305, 
310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 400, 405, 410, 
415, 420, 425, 430, 435, 440, 445, 450, 455, 500, 505, 510, 515, 
520, 525, 530, 535, 540, 545, 550, 555, 600, 605, 610, 615, 620, 
625, 630, 635, 640, 645, 650, 655, 700, 705, 710, 715, 720, 725, 
730, 735, 740, 745, 750, 755, 800, 805, 810, 815, 820, 825, 830, 
835, 840, 845, 850, 855, 900, 905, 910, 915, 920, 925, 930, 935, 
940, 945, 950, 955, 1000, 1005, 1010, 1015, 1020, 1025, 1030, 
1035, 1040, 1045, 1050, 1055, 1100, 1105, 1110, 1115, 1120, 1125, 
1130, 1135, 1140, 1145, 1150, 1155, 1200, 1205, 1210, 1215, 1220, 
1225, 1230, 1235, 1240, 1245, 1250, 1255, 1300, 1305, 1310, 1315, 
1335, 1340, 1345, 1350, 1355, 1400, 1405, 1410, 1415, 1420, 1425, 
1430, 1505, 1510, 1515, 1520, 1525, 1530, 1535, 1540, 1545, 1550, 
1555, 1600, 1605, 1610, 1615, 1620, 1625, 1630, 1635, 1640, 1645, 
1650, 1655, 1700, 1705, 1710, 1715, 1720, 1725, 1730, 1735, 1740, 
1745, 1750, 1755, 1800, 1805, 1810, 1815, 1820, 1825, 1830, 1835, 
1840, 1845, 1850, 1855, 1900, 1905, 1910, 1915, 1920, 1925, 1930, 
1935, 1940, 1945, 1950, 1955, 2000, 2005, 2010, 2015, 2020, 2025, 
2030, 2035, 2040, 2045, 2050, 2055, 2100, 2105, 2110, 2115, 2120, 
2125, 2130, 2135, 2140, 2145, 2150, 2155, 2200, 2205, 2210, 2215, 
2220, 2225, 2230, 2235, 2240, 2245, 2250, 2255, 2300, 2305, 2310, 
2315, 2320, 2325, 2330, 2335, 2340, 2345, 2350, 2355, 0, 5, 10, 
15, 20, 25, 30, 35, 40, 45, 50, 55, 100, 105, 110, 115, 120, 
125, 130, 135, 140, 145, 150, 155, 200, 205, 210, 215, 220, 225, 
230, 235, 240, 245, 250, 255, 300, 305, 310, 315, 320, 325, 330, 
335, 340, 345, 350, 355, 400, 405, 410, 415, 420, 425, 430, 435, 
440, 445, 450, 455, 500, 505, 510, 515, 520, 525, 530, 535, 540, 
545, 550, 555, 600, 605, 610, 615, 620, 625, 630, 635, 640, 645, 
650, 655, 700, 705, 710, 715, 720, 725, 730, 735, 740, 745, 750, 
755, 800, 805, 810, 815, 820, 825, 830, 835, 840, 845, 850, 855, 
900, 905, 910, 915, 920, 925, 930, 935, 940, 945, 950, 955, 1000, 
1005, 1010, 1015, 1020, 1025, 1030, 1035, 1040, 1045, 1050, 1055, 
1100, 1105, 1110, 1115, 1120, 1125, 1130, 1135, 1140, 1145, 1150, 
1155, 1200, 1205, 1210, 1215, 1220, 1225, 1230, 1235, 1240, 1245, 
1250, 1255, 1300, 1305, 1310, 1315, 1335, 1340, 1345, 1350, 1355, 
1400, 1405, 1410, 1415, 1420, 1425, 1430, 1435, 1505, 1510, 1515, 
1520, 1525, 1530, 1535, 1540, 1545, 1550, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0), .Dim = c(500L, 3L), .Dimnames = list(NULL, c("Date", 
"Time", "X2")))
  • 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-12T17:36:22+00:00Added an answer on June 12, 2026 at 5:36 pm
    library("plyr")
    resample <- function(x, ...) x[sample.int(length(x), ...)] # from `sample` documentation
    D2 <- as.matrix(ddply(as.data.frame(D1), .(Date), function(DF) {
      intime <- which(DF$Time >= 630 & DF$Time <= 1030)
      if (length(intime) > 0) {
        DF[resample(intime,1),"X2"] <- 1
      }
      DF
    }))
    

    This turns the matrix into a data.frame, uses ddply from plyr to look at a day-at-a-time, and then the anonymous function finds the indexes of the entries that fall within your given time range, picks one randomly (using sample via resample) and assigns a 1 to that. The whole thing is turned back into a matrix (since that is how it started).

    Rather than show the entire output D2, just look at the differences from D1

    > which(D2 != D1, arr.ind = TRUE)
         row col
    [1,] 117   3
    [2,] 405   3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following schema / data / output how would I format a SQL
If I am given some data in the following format: data = [ ['Airbus',
While following numerous D3 examples, data usually gets formatted in the format given in
Given delimited data in the following format, how can I insert and delete columns?
Given data in the following format (tag_uri image_uri image_uri image_uri ...), I need to
Given a set of delimited data in the following format: 1|Star Wars: Episode IV
Given the following data/schema: DECLARE @t1 TABLE ( Id int NOT NULL ) DECLARE
I have an odd linq subquery issue. Given the following data structure: Parents Children
Given the following JSON data: [ { pk: 2, model: corkboard.announcement, fields: { body:
Given the following example data: Users +--------------------------------------------------+ | ID | First Name | Last

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.