Hi list,
As I understand statements within with() are local to what is enclosed
within its expression.
As some excellent examples given to me previously have illustrated it is
nevertheless possible to assign the evaluation of an expression to an
external variable like x <- with(data, if(..))
During a "normalisation" phase of data read from a database I have a
long
list of statements of the type
participant$longfieldname[is.na(participant$longfieldname)]<-expr(...)
or similar that makes cumbersome reading. (participant is a table of
demographic data)
If there a neat way to do something of the sort
"participant<-with(participant,{...})"
it would make nicer reading.
Apparently attach(), detach() would not do as
fieldname<-expr(fieldname)
creates a new variable and not a change to the value of the field!
Saluti,
Antonio Prioglio
--
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
Aristoteles
/"\
\ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
X - AGAINST MS ATTACHMENTS
/ \
http://www.gnu.org/philosophy/no-word-attachments.html
On Thursday 15 July 2004 03:01, Antonio Prioglio wrote:> Hi list, > As I understand statements within with() are local to what is > enclosed within its expression. > > As some excellent examples given to me previously have illustrated it > is nevertheless possible to assign the evaluation of an expression to > an external variable like x <- with(data, if(..)) > > During a "normalisation" phase of data read from a database I have a > long list of statements of the type > participant$longfieldname[is.na(participant$longfieldname)]<-expr(... >) or similar that makes cumbersome reading. (participant is a table of > demographic data) > > If there a neat way to do something of the sort > "participant<-with(participant,{...})"You may want to take a look at ?transform Deepayan
You could copy them back out at the end of your with like this:
data(iris) # fetch test data
with(iris, {
Sepal.Length[Sepal.Length > 5] <- 5
Sepal.Width <- Sepal.Width + 10
for(n in names(iris)) iris[n] <<- get(n)
} )
Antonio Prioglio <a.prioglio <at> city.ac.uk> writes:
:
: Hi list,
: As I understand statements within with() are local to what is enclosed
: within its expression.
:
: As some excellent examples given to me previously have illustrated it is
: nevertheless possible to assign the evaluation of an expression to an
: external variable like x <- with(data, if(..))
:
: During a "normalisation" phase of data read from a database I have a
long
: list of statements of the type
: participant$longfieldname[is.na(participant$longfieldname)]<-expr(...)
: or similar that makes cumbersome reading. (participant is a table of
: demographic data)
:
: If there a neat way to do something of the sort
: "participant<-with(participant,{...})"
:
: it would make nicer reading.
:
: Apparently attach(), detach() would not do as
: fieldname<-expr(fieldname)
: creates a new variable and not a change to the value of the field!
:
: Saluti,
: Antonio Prioglio
: