[R] inplace assignment

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Jun 16 12:15:35 CEST 2006


"David Hugh-Jones" <davidhughjones at gmail.com> writes:

> I get tired of writing, e.g.
> 
> 
> data.frame[some.condition & another.condition, big.list.of.columns] <-
> paste(data.frame[some.condition & another.condition,
> big.list.of.columns], "foobar")
> 
> 
> I would a function like:
> 
> inplace(paste(data.frame[some.condition & another.condition,
> big.list.of.columns], "foobar"))
> 
> which would take the first argument of the inner function and assign
> the function's result to it.
> 
> Has anyone done something like this? Are there simple alternative
> solutions that I'm missing?

Well, I'd consider

cc <- some.condition & another.condition
l <- big.list.of.columns
mydf[cc,l] <- paste(mydf[cc,l], "foobar)

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list