I don’t find the help page for the replace function from the base package to be very helpful. Worst part, it has no examples which could help understand how it works.
Could you please explain how to use it? An example or two would be great.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
If you look at the function (by typing it’s name at the console) you will see that it is just a simple functionalized version of the
[<-function which is described at?"[".[is a rather basic function to R so you would be well-advised to look at that page for further details. Especially important is learning that the index argument (the second argument inreplacecan be logical, numeric or character classed values. Recycling will occur when there are differing lengths of the second and third arguments:You should “read” the function call as” “within the first argument, use the second argument as an index for placing the values of the third argument into the first”:
Character indexing for a named vector:
Logical indexing: