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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:11:27+00:00 2026-05-13T16:11:27+00:00

In R , how can I overwrite the first values of a long vector

  • 0

In R, how can I overwrite the first values of a long vector with values obtained from a file, where the file contains possibly fewer values?

Example:

# fill with n=100 values
vec1 <- runif(100)

# read m values, where m <= n
vec2 <- scan("myfile", sep="\n")

# now want to set the first m values of vec1 
# to the values in vec2

I could walk through vec2 and copy the values into vec1, but I think there should be a more efficient way?

  • 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-13T16:11:28+00:00Added an answer on May 13, 2026 at 4:11 pm
    R> set.seed(1)
    R> vec1 <- runif(100)
    R> vec2 <- 1:20
    
    R> vec1[1:length(vec2)] <- vec2
    R> vec1
      [1]  1.00000  2.00000  3.00000  4.00000  5.00000  6.00000  7.00000  8.00000
      [9]  9.00000 10.00000 11.00000 12.00000 13.00000 14.00000 15.00000 16.00000
     [17] 17.00000 18.00000 19.00000 20.00000  0.93471  0.21214  0.65167  0.12556
     [25]  0.26722  0.38611  0.01339  0.38239  0.86969  0.34035  0.48208  0.59957
     [33]  0.49354  0.18622  0.82737  0.66847  0.79424  0.10794  0.72371  0.41127
     [41]  0.82095  0.64706  0.78293  0.55304  0.52972  0.78936  0.02333  0.47723
     [49]  0.73231  0.69273  0.47762  0.86121  0.43810  0.24480  0.07068  0.09947
     [57]  0.31627  0.51863  0.66201  0.40683  0.91288  0.29360  0.45907  0.33239
     [65]  0.65087  0.25802  0.47855  0.76631  0.08425  0.87532  0.33907  0.83944
     [73]  0.34668  0.33377  0.47635  0.89220  0.86434  0.38999  0.77732  0.96062
     [81]  0.43466  0.71251  0.39999  0.32535  0.75709  0.20269  0.71112  0.12169
     [89]  0.24549  0.14330  0.23963  0.05893  0.64229  0.87627  0.77891  0.79731
     [97]  0.45527  0.41008  0.81087  0.60493
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application reads settings from a conf file first, and then those options can
can i override Convert.ToDateTime() ? I don't want 100 times or more check if
First of all, the description may be a little long with lots of code,
I created a palette which contains values, and i created a DropDownChoice ddcdomaines with
Follow on from a previous question One first screen activity I am clicking a
Hi I have a question. Wondering how do I get certain values from the
My goal is to take in a CSV file which contains approximately 4 million
I have Implemented Code to download a File from Internet, But I am getting
I'm trying to reference a file stored in my working directory, so it can
I know you can override delete and save methods in DJango models, but can

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.