Skip to content
Back to formatted view

Raw Message

Message-ID: <04FA967CF3C1A14AB593785C317F043506D2680D@HERMES4.imim.es>
Date: 2018-12-10T10:35:03Z
From: Subirana Cachinero, Isaac
Subject: repeating the same variable in formula
In-Reply-To: <d44a5f47-5dd5-e652-1c43-d6390438f60b@sapo.pt>

Thank you for your response.
In fact, I use the formula environament to select variables, as part of the code of another function.
I would like to allow the user to select the same variable more than once.
The use of I() may partly solve the problem. However, I would like attr(terms(g),"term.labels") would return a vector with as many components as variables including repetitions. And using I() function, there would be some work remaining to split "I(age + age)" into "age", "age", taking into account that in other examples variable may include white spaces or other characters within ` `.

Isaac.

-----Mensaje original-----
De: Rui Barradas [mailto:ruipbarradas at sapo.pt] 
Enviado el: lunes, 10 de diciembre de 2018 11:27
Para: Subirana Cachinero, Isaac; r-help at r-project.org
Asunto: Re: [R] repeating the same variable in formula

Hello,

The formulas

y ~ cholesterol + age + age

and

y ~ cholesterol + age

are the same formula.
If you want 'age' twice, maybe

g <- y ~ cholesterol + I(age + age)
attr(terms(g), "term.labels")
#[1] "cholesterol"  "I(age + age)"


Hope this helps,

Rui Barradas

?s 06:49 de 10/12/2018, Subirana Cachinero, Isaac escreveu:
> y ~ cholesterol + age + age