Using rscript
Assign the name ‘today’ to today’s date in the following format: Feb 15 2018, and print it. Then, check the class of ‘today’ with class(today). Show the class of ‘today’. b) The class of ‘today’ in a) is not “Date”. Please convert it to the class ‘Date’ and assign the name ‘today.Date’. Then, check the class of ‘today.Date’ with class(today.Date). Show the class of ‘today.Date’.
Firstly taking the variable today and assigning value 11 Sept 2019
> today<-"10 Feb 2019"
Now to print the value we use the print function in R
> print(today)
now class() function will give the data type
> class(today)
now it will print as character
now to convert character to Date we have a function as.Date("date",format)
now we assign the variable today.Date using this function
today.Date<-as.Date(today, "%d%B%Y")
now check the class of today.Date variable
>class(today.Date)
now you will see the class as Date
Using as.Date() function we can convert from "character" to "Date" class
check the screenshot below for clear understanding:
##for any queries do comment below feel free to comment
Get Answers For Free
Most questions answered within 1 hours.