[R] simplify source code

jim holtman jholtman at gmail.com
Thu Dec 1 14:53:14 CET 2011


measurements[[colname]]

?'[['



On Thu, Dec 1, 2011 at 8:34 AM, Christof Kluß <ckluss at email.uni-kiel.de> wrote:
> 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
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list