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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:55:41+00:00 2026-06-16T21:55:41+00:00

Suppose we have a dataframe or matrix with one column specifying an integer value

  • 0

Suppose we have a dataframe or matrix with one column specifying an integer value N as below (col 5).
Is there a vector approach to repopulate the object such that each row gets copied N times?

> y
            [,1]       [,2]        [,3]        [,4] [,5]
[1,] -0.02738267  0.5170621 -0.01644855  0.48830663    1
[2,] -0.30076544  1.8136359  0.02319640 -1.59649330    2
[3,]  1.73447245  0.4043638 -0.29112385 -0.25102988    3
[4,]  0.01025271 -0.4908636  0.80857300  0.08137033    4

The result would be as follows.

[1,] -0.02738267  0.5170621 -0.01644855  0.48830663    1
[2,] -0.30076544  1.8136359  0.02319640 -1.59649330    2    
[2,] -0.30076544  1.8136359  0.02319640 -1.59649330    2
[3,]  1.73447245  0.4043638 -0.29112385 -0.25102988    3
[3,]  1.73447245  0.4043638 -0.29112385 -0.25102988    3
[3,]  1.73447245  0.4043638 -0.29112385 -0.25102988    3
[4,]  0.01025271 -0.4908636  0.80857300  0.08137033    4
[4,]  0.01025271 -0.4908636  0.80857300  0.08137033    4
[4,]  0.01025271 -0.4908636  0.80857300  0.08137033    4
[4,]  0.01025271 -0.4908636  0.80857300  0.08137033    4

Another question would be how to jitter the newly populated rows, such that there is not compute overlap of the newly copied data.

  • 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-16T21:55:42+00:00Added an answer on June 16, 2026 at 9:55 pm

    Some made-up data:

    y <- cbind(matrix(runif(16), 4, 4), 1:4)
    

    Just do:

    z <- y[rep(seq_len(nrow(y)), y[,5]), ]
    #            [,1]       [,2]       [,3]      [,4] [,5]
    #  [1,] 0.5256007 0.07467979 0.95189484 0.2887943    1
    #  [2,] 0.3083967 0.03518523 0.08380005 0.9168161    2
    #  [3,] 0.3083967 0.03518523 0.08380005 0.9168161    2
    #  [4,] 0.8549639 0.79452728 0.22483537 0.4452553    3
    #  [5,] 0.8549639 0.79452728 0.22483537 0.4452553    3
    #  [6,] 0.8549639 0.79452728 0.22483537 0.4452553    3
    #  [7,] 0.5453508 0.47633523 0.51522514 0.3936340    4
    #  [8,] 0.5453508 0.47633523 0.51522514 0.3936340    4
    #  [9,] 0.5453508 0.47633523 0.51522514 0.3936340    4
    # [10,] 0.5453508 0.47633523 0.51522514 0.3936340    4
    

    And I am not sure what you mean by “jitter”, but maybe

    z <- z + runif(z) / 1000
    

    ?

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

Sidebar

Related Questions

Suppose I have a dataframe like this one: df <- data.frame (id = c(a,
Suppose I have a DataFrame with 100k rows and a column name . I
Suppose I have the following DataFrame (timeseries, first column is a DateTimeIndex) atn file
Suppose I have a column in a dataframe: A A A A B B
I have two dataframes and I wish to insert the values of one dataframe
Suppose I have this : item_one = Object.find(1) rescue item_one, value = [Object.first, true]
Suppose I have a dataframe 'H', like so C1 C2 a 1 b 1
Suppose I have a Pandas dataframe df has columns a,b,c,d...z . And I want
Suppose I have the example TimeSeries below: ts = pandas.TimeSeries({'a':[1,2,3,4,5], 'b':[6,7,8,9,10]}) The best method
Suppose I have a data.frame that's completely numeric . If I make one entry

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.