Message-ID: <FF8208EE-1E40-4C3B-B58D-DCEA21FA518A@comcast.net>
Date: 2016-05-24T21:39:37Z
From: David Winsemius
Subject: Sprintf to call data frame from environment
In-Reply-To: <BLU436-SMTP159813C8E5D06B4BB0174F3D94F0@phx.gbl>
> On May 24, 2016, at 2:01 PM, Beatriz <aguitatierra at hotmail.com> wrote:
>
>
> In my environment I have a data frame called Samples_1.txt.
> From this data frame I need to get variable V1. My code doesn't work. Thanks!
>
> $V1
>
> Note: I need to do it in this way because I have the code into a for loop.
You are treating this as if R were a macro processor, which it's not. The only function that lets you pull in a data-object from the store of named objects using a character vector is `get`, so perhaps:
get( sprintf("Samples_%s.txt", 1) )$V1
And if you were considering the next step of hoping to pass a computed item to `$`, then forget that as well, and learn to use `[`.
--
David Winsemius
Alameda, CA, USA