Message-ID: <4B00AA60.5020207@stats.uwo.ca>
Date: 2009-11-16T01:26:56Z
From: Duncan Murdoch
Subject: How to name a tag in a list or a data.frame from a string?
In-Reply-To: <366c6f340911151715m1b28473y2b1f1b0fe8baa76c@mail.gmail.com>
On 15/11/2009 8:15 PM, Peng Yu wrote:
> Suppose I have a string variable
>
> string='some_string'
>
> Now I want to have a list, where <tag> is the same as the string in
> the variable string. I'm wondering if this is possible in R.
>
> list(<tag>=1:3)
> data.frame(<tag>=1:3)
The most straightforward way is
x <- list(1:3)
names(x) <- string
y <- data.frame(dummy=1:3)
names(y) <- string
You can also build expressions and parse and evaluate them, but the
lines above are the easiest way.
Duncan Murdoch