[R] simplify source code

Christof Kluß ckluss at email.uni-kiel.de
Thu Dec 1 14:34:14 CET 2011


Hi

now I'd like to do

for (colname in c('ColName1','ColName2','ColName3')) {		
     dat <- measurements$colname

But that does not work, though I can write

measurements$"C1" (same as measurements$C1)
(but different to measurements["C1"]!)

Can you give me a hint?

greetings
Christof



Am 26-11-2011 23:30, schrieb Christof Kluß:
> Hi
>
> I would like to shorten
>
> mod1 <- nls(ColName2 ~ ColName1, data = table, ...)
> mod2 <- nls(ColName3 ~ ColName1, data = table, ...)
> mod3 <- nls(ColName4 ~ ColName1, data = table, ...)
> ...
>
> is there something like
>
> cols = c(ColName2,ColName3,ColName4,...)
>
> for i in ...
> mod[i-1] <- nls(ColName[i] ~ ColName1, data = table, ...)
>
> I am looking forward to help
>
> Christof
>



More information about the R-help mailing list