[R] inplace assignment

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Fri Jun 16 12:31:41 CEST 2006


I do not fully understand your question but how about :

 inplace <- function( df, cond1, cond2, cols, suffix ){
 
  w  <- which( cond1 & cond2 )
  df <- df[ w, cols ]
  paste(df, suffix)
  return(df)
 }


BTW, did you mean "colnames(df) <- paste(colnames(df), suffix)" instead
of "paste(df, suffix)" ?

Regards, Adai



On Fri, 2006-06-16 at 10:23 +0100, David Hugh-Jones wrote:
> 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?
> 
> Cheers
> David
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



More information about the R-help mailing list