简体   繁体   中英

How to name a variable or data.frame with the date in R

I have a function that outputs a data frame, and I would like it to name the data with the current date somewhere in the name. Ideally, something like 20170517.data or the like.

If I can figure out how to name just an object or variable like this, I can include it in my function.

I've tried:

as.character(sys.Date,date) <- dataframe
paste(sys.Date,data,sep="") <- dataframe

I'd appreciate any help!

You can do this with assign

my_data <- rnorm(10)
assign(paste0(Sys.Date(), ".data"), value = my_data)

This will create variable of the form "2017-05-17.data".

If you wish to create a dfname(sys.date) straight from an excel file (or other) you can use assign(paste0("prefix",Sys.Date()), value = read_excel("/directory/filename.xlsx"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM