[R] Sprintf to call data frame from environment

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Tue May 24 23:38:54 CEST 2016


It is not clear (at least to me) what your actual task is.  But, if Samples_1.txt is the actual name of a data frame that exists in memory (and not a filename), then you need to wrap the sprintf() in a get() function.

get(sprintf("Samples_%s.txt", 1))$V1

I am no expert  on "computing on the language" in R, but I can't help but think you are going about your task in the wrong way.  If you provide more detail about what you are trying to do, someone will probably be able to provide you a solution where you don't need to do it this way.


Hope this is helpful,

Dan

Daniel Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Beatriz
> Sent: Tuesday, May 24, 2016 2:01 PM
> To: r-help at r-project.org
> Subject: [R] Sprintf to call data frame from environment
> 
> 
> 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!
> 
> 	sprintf("Samples_%s.txt", 1)$V1
> 
> Note: I need to do it in this way because I have the code into a for loop.
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list