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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:19:08+00:00 2026-05-26T22:19:08+00:00

I have a dataframe in R that I want to randomize, keeping the first

  • 0

I have a dataframe in R that I want to randomize, keeping the first column like it is but randomizing the last two columns together, so that values that appear in the same rows in these columns will appear in the same row both after randomizing. So if I started with this:

1 a b c 
2 d e f 
3 g h i 

when randomized it might look like:

1 a e f 
2 d h i 
3 g b c 

I know that sample works fine but does it conserve the columns equivalence?

  • 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-26T22:19:09+00:00Added an answer on May 26, 2026 at 10:19 pm
    > t <- data.frame(matrix(nrow=4,ncol=10,data=1:40))
    > t
        X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
        1  1  5  9 13 17 21 25 29 33  37
        2  2  6 10 14 18 22 26 30 34  38
        3  3  7 11 15 19 23 27 31 35  39
        4  4  8 12 16 20 24 28 32 36  40
    > columns_to_random <- c(8,9,10)
    > t[,columns_to_random] <- t[sample(1:nrow(t),size=nrow(t)), columns_to_random]
    >   X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
        1  1  5  9 13 17 21 25 32 36  40
        2  2  6 10 14 18 22 26 29 33  37
        3  3  7 11 15 19 23 27 30 34  38
        4  4  8 12 16 20 24 28 31 35  39
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataframe with a column of integers that I would like to
I have a dataframe that I want to reshape; my reshape code: matchedlong <-
I want to convert a column of my dataframe into another one. I have
I have a dataframe with columns labeled A,B & C. I want to add
I have a dataframe that I would like to plot in a similar way
I have a column in a dataframe that contains an ordered factor. I summarize
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that looks like this: > TimeOffset, Source,
I have a dataframe with numeric entries like this one test <- data.frame(x =
Suppose I have a dataframe like this one: df <- data.frame (id = c(a,

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.