Hello R Users,
I'm wondering if there exists any elegant and simple way to do the
following: I have a data.frame X fills in numbers. I have a vector y with
numbers as well. Every value in X that is equal to any values in y should
be replaced by e.g. 1. Any idea?
Robert
Robert Ruser robert.ruser at gmail.com writes:
Hello R Users,
I'm wondering if there exists any elegant and simple way to do the
following: I have a data.frame X fills in numbers. I have a vector y with
numbers as well. Every value in X that is equal to any values in y should
be replaced
On 11/06/2010 11:36 AM, Robert Ruser wrote:
Hello R Users,
I'm wondering if there exists any elegant and simple way to do the
following: I have a data.frame X fills in numbers. I have a vector y with
numbers as well. Every value in X that is equal to any values in y should
be replaced by e.g. 1.
Thank you vary much Ben and Erik.
It's exactly what I want. Below is my a little modified example.
set.seed(12345)
X = sample(c(40:60),40,replace=TRUE)
x = matrix(X,nc=5)
y = c(40,43,55,60)
x[x %in% y] - -1
__
R-help@r-project.org mailing list
4 matches
Mail list logo