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

The Archive Base Latest Questions

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

I have a matrix of one column and 6 rows. I would like to

  • 0

I have a matrix of one column and 6 rows. I would like to replicate that column i times but change one value randomly each time, and after each iteration, calculate the mean and variance across all columns.

For example:

values = rnorm(6, 6, 1); matrix1 = matrix(values, 6)

After i=1, would look like:

values2 = values
values2[sample(1:6, 1)] = values2[sample(1:6, 1)]+runif(1, 0, 1)
matrix2 = matrix(c(values, values2), 6)

At the end, I would like to output a data frame that looks like so:

i   mean   var
1   1.23  2.31
2   1.24  2.33 etc...

For many i‘s. I imagine there is a way to do this with loops, but my skills are not such that I can figure it out. Thanks for all 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-30T22:00:43+00:00Added an answer on May 30, 2026 at 10:00 pm

    If you know how many times you’re doing this, it would be best to construct your final matrix beforehand, especially if i is large. However, without that:

    jitter.func <- function(x, vec) {
      cell <- sample(1:length(vec), 1)
      vec[cell] <- vec[cell] + runif(1, 0, 1)
    
      return(c(mean=mean(vec), var=var(vec)))
    }
    
    
    i <- 10
    sapply(1:i, jitter.func, vec=values)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one column matrix with n rows. I want difference between row 2
In R: I have a matrix with one column classified by 8 types: a,
I have matrix (a) with (1:10),<10 x 1> double. I would like to copy
i have a text file that holds a 2-dimensional matrix. it looks like the
I have a view that displays a table: rows represent days - one row
I have a cell matrix with two columns (no headers). Column one contains ticker
I have a large matrix mdat (1000 rows and 16 columns) contains first column
I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code
I have a 40x16 matrix or 8 5x16 one below the other i.e. aligned
I have made one function in which I am passing a matrix and returning

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.