s-news
[Top] [All Lists]

[no subject]

To: <s-news@wubios.wustl.edu>
Subject:
From: "Boylan, Richard" <rboylan@bus.olemiss.edu>
Date: Fri, 30 Nov 2001 10:20:31 -0600
Thread-index: AcF5uu3F/mP/E+V4EdWO8QABAxxsSA==

 1. I will repost my original question. 2. Reposts
the original solution that I posted. 3. Contains the
correction of 2. 4. Contains the other
solutions that I received after posting 2.

Of course thanks for all the answers!!!!!  My apologies
I lost anyone’s answer.

1. This is a simple question that I could not find good keywords to search
through the archives.
Let
data <- data.frame( x = c(1,2,4,4,3,5,6), y = c(1,2,3,4,5,6,7) )
What I would like to do is change the values of y for values of x that
belong to some list.
So, for instance,
data$y[ data$x == 1 | data$x == 4] <- 3
will change the values of y to 3 if x is 1 or 4.
I would like to be able to do that for a long list of values of x, so adding
all these | is not proctical.
So, what I have in mind is something like
list.x <- list(1,4)
data$y[ data$x in list.x] <- 3.
Of course there is no such command, so I was wondering how does one
do that.

2. data$y[ data$x %in% c(1,4)]  Tom Stockton

3.
Please note: %in% is part of the hmisc library, not the standard distribution. Try
> find("%in%")

Alternatively, he writes a new function %IN%
"%IN%" <- function(a,b) is.element(a,b)
data$y[ data$x %IN% list.x ] <- 3


4.
Sean Keenan, Andy Liaw, Steven Smith, Leonid Gibianski, Nick Ellis, Vadim Kutsyy, David Patterson:
vec <- c(1,4)
data$y[is.element(data$y, vec)] <- 3

Jose Pieheiro, Samantha Low Choy, Don McKenzie, Jim Pratt:
data[!is.na(match(data$x, c(1,4))), "y"] <- 3

Pierre Delfosse, Rod Tjoelker:
data$y[!is.na(match(data$x,c(1,4)))]

<Prev in Thread] Current Thread [Next in Thread>
  • [no subject], Boylan, Richard <=