Hi Everyone, I am trying a very simple task to append the Timestamp with a variable name so something like a_2012_09_27_00_12_30 <- rnorm(1,2,1). Tried some commands but it doesn't work out well. Hope someone has some answer on it. Session Info R version 2.15.1 (2012-06-22) Platform: i386-apple-darwin9.8.0/i386 (32-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] chron_2.3-42 twitteR_0.99.19 rjson_0.2.9 RCurl_1.91-1 bitops_1.0-4.1 tm_0.5-7.1 RMySQL_0.9-3 DBI_0.2-5 loaded via a namespace (and not attached): [1] slam_0.1-24 tools_2.15.1 Statement I tried : b <- unclass(Sys.time()) b = 1348812597 c_b <- rnorm(1,2,1) Works perfect but doesn't show me c_1348812597. Best Regards, Bhupendrasinh Thakre [[alternative HTML version deleted]]
Hi! 28.09.2012 09:13, Bhupendrasinh Thakre wrote:> Statement I tried : > > b <- unclass(Sys.time()) > b = 1348812597 > c_b <- rnorm(1,2,1)Do you mean this: --- code --- > df<-data.frame("x"=0,"y"=0) > colnames(df) [1] "x" "y" > colnames(df)[2]<-paste("b",unclass(Sys.time()),sep="_") > colnames(df) [1] "x" "b_1348813791.55393" --- code --- HTH, Kimmo
Hello, Try the following: b <- unclass(Sys.time()) eval(parse(text=paste("c_",b," <- rnorm(1,2,1)",sep=""))) ls() Regards, Pascal Le 28/09/2012 15:13, Bhupendrasinh Thakre a ?crit :> > Hi Everyone, > > I am trying a very simple task to append the Timestamp with a variable name so something like > a_2012_09_27_00_12_30 <- rnorm(1,2,1). > > Tried some commands but it doesn't work out well. Hope someone has some answer on it. > > Session Info > > R version 2.15.1 (2012-06-22) > Platform: i386-apple-darwin9.8.0/i386 (32-bit) > > locale: > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] chron_2.3-42 twitteR_0.99.19 rjson_0.2.9 RCurl_1.91-1 bitops_1.0-4.1 tm_0.5-7.1 RMySQL_0.9-3 DBI_0.2-5 > > loaded via a namespace (and not attached): > [1] slam_0.1-24 tools_2.15.1 > > Statement I tried : > > b <- unclass(Sys.time()) > b = 1348812597 > c_b <- rnorm(1,2,1) > > Works perfect but doesn't show me c_1348812597. > > Best Regards, > > > Bhupendrasinh Thakre > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
On Sep 27, 2012, at 11:13 PM, Bhupendrasinh Thakre wrote:> > Hi Everyone, > > I am trying a very simple task to append the Timestamp with a variable name so something like > a_2012_09_27_00_12_30 <- rnorm(1,2,1).If you want to assign a value to a character-name you need to use ... `assign`. You cannot just stick a numeric value which is what you get with sys.Time() on the LHS of a "<-" and expect R to intuit what you intend. ?assign assign( "a_2012_09_27_00_12_30" , rnorm(1,2,1) ) assign( as.character(unclass(Sys.time())) , rnorm(1,2,1) ) (I would have thought you wanted to format that sys.Time result:)> format(Sys.time(), "%Y_%m_%d_%H_%M_%S")[1] "2012_09_27_23_32_40"> assign(format(Sys.time(), "%Y_%m_%d_%H_%M_%S"), rnorm(1,2,1) ) > grep("^2012", ls(), value=TRUE)[1] "2012_09_27_23_33_45"> > Tried some commands but it doesn't work out well. Hope someone has some answer on it. > > Session Info > > R version 2.15.1 (2012-06-22) > Platform: i386-apple-darwin9.8.0/i386 (32-bit) > > locale: > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] chron_2.3-42 twitteR_0.99.19 rjson_0.2.9 RCurl_1.91-1 bitops_1.0-4.1 tm_0.5-7.1 RMySQL_0.9-3 DBI_0.2-5 > > loaded via a namespace (and not attached): > [1] slam_0.1-24 tools_2.15.1 > > Statement I tried : > > b <- unclass(Sys.time()) > b = 1348812597 > c_b <- rnorm(1,2,1) > > Works perfect but doesn't show me c_1348812597. > > Best Regards, > > > Bhupendrasinh Thakre > [[alternative HTML version deleted]]BT; Please learn to post in plain text. It's really very simple with gmail. -- David Winsemius, MD Alameda, CA, USA