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?