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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:11:20+00:00 2026-06-12T19:11:20+00:00

I have a 1000×1 vector (1000 rows and 1 column). I want to get

  • 0

I have a 1000×1 vector (1000 rows and 1 column). I want to get elements in pairs (row 1 and row 2, row 3 and row 4, row 5 and row 6, etc.)

Here’s what I have so far

for (j in 1: ncol(total_loci)){
    for (i in 1: sample_size){
    # a pair
    genotype[i]<- paste(total_loci[i, j], total_loci[i+1,j], sep="")
    }
}

Genotype should thus be a 500×1 vector (500 rows and 1 column) containing the genotype. Assume that my for-loops are correct. I think my I needs to skip every other index — so my i should start at 1 then 3, 5, 7, 9, etc. The variable total_loci is of class data frame.

  • 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-12T19:11:22+00:00Added an answer on June 12, 2026 at 7:11 pm

    You should try to use vectorized solutions where possible. They’re usually more memory efficient and faster than loops.

    In this case, you can use seq to generate an index vector for every other element. Then you can use that index vector to subset the original vector in pairs.

    # sample data
    x <- replicate(5, sample(LETTERS, 1000, replace=TRUE), simplify=FALSE)
    x <- as.data.frame(x, stringsAsFactors=FALSE)
    names(x) <- paste("V",1:NCOL(x), sep="")
    
    # function to concatenate every other observation as a pair
    f <- function(x) {
      s <- seq(2, length(x), 2)
      paste(x[s-1], x[s], sep="")
    }
    
    # run algorithm for each column
    y <- as.data.frame(lapply(x, f), stringsAsFactors=FALSE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say, I have 1000 elements in a array and I want to search
I have 1000 rows of data but need to only display 100 rows at
I have 1000 files in a directory. I'm on a solaris machine I want
I have the following query which have 1000 rows select staffdiscountstartdate,datediff(day,groupstartdate,staffdiscountstartdate), EmployeeID from tblEmployees
I have 1000's of strings similar to CN=Joe Smith,OU=Students,DC=Domain,DC=Edu and I want to find
Regarding iPhone Map Kit cluster pinpoints: I have 1000's of marks that I want
I want to sort a list of strings. I have 1000 addresses (some custom
I have 1000 to 1200 JSP files in my project, and I want to
I have a directory in which I have 1000 txt.files in it. I want
I have 1000 float datas in an array. I want to separate into different

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.