| replace {base} | R Documentation |
Replace Values in a Vector
Description
Replace vector elements at given indices by given values.
Usage
replace(x, list, values)
Arguments
x |
a |
list |
an index vector, as for |
values |
replacement values, recycled if necessary. |
Value
A vector with the values replaced.
Note
x is unchanged: remember to assign the result.
References
Becker RA, Chambers JM, Wilks AR (1988). The New S Language. Chapman and Hall/CRC, London. ISBN 053409192X.
Examples
x <- 1:5
replace(x, c(2, 5), c(8, 9)) # returns a modified copy
identical(x, 1:5) # TRUE, x is not modified
[Package base version 4.6.2 Index]