Data analysis with R language (9)--Date and time format 1

Source: Internet
Author: User
Tags month name

The R language is open source and can be run on a variety of platforms (Linux, Windows, MacOS, and so on). Many of R's packages are written by the R language, LaTeX, Java, and the most commonly used C language and Fortran. This article introduces you to the date format data of the R language.
#日期型数据
The date form in R is: as.date (); stored in numerical form;
For the format of the rule, format is not required, and if the input is irregular, it can be read in the format specified by format;
Standard format:
Year-month-day or year/month/day; if it is not the above two formats, an error will be provided;
As. Date (' 23-2013-1 ')
Error in Charto according to date (x): string format is not standard clear
> As. Date (' 23-2013-1 ', format= '%d-%y-%m ')
[1] "2013-01-23"

Format

Significance

%d

Days in the month

%m

month, expressed as a number

%b

month, abbreviation

%B

month, full month name, English

%y

Year, expressed as a two-digit number

%Y

Year, expressed as a four-digit number

#其它日期相关函数
Weekdays () The day of the week on which the date object is located;
months () the month of the date object;
Quarters () The quarter of the Date object;
#POSIX类
The POSIXct class stores date/time values as the number of seconds since January 1, 1970, while the PO Sixlt class stores them as a list with elements for second, minute, hour, day, month, and year, among others. The
POSIXct is stored in seconds starting January 1, 1970, if negative, before 1970, and positive for 1970. The
Posixlt is stored as a list: year, month, day, time, minute, second,
MyDate = as. Posixlt (' 2005-4-19 7:01:00 ')
names (mydate)
By default, the date is separated by/or-and the time is delimited by: the
Input standard format is: Date Time (date is separated from time) the standard format for
time is: time: Minute or hour: minute: seconds;
If the input format is not a standard format, you also need to use the Strptime function to specify with format;
#生成案例数据
Dates <-C ("2009-09-28", "2010-01-15")
Times <-C ("23:12:55", "10:34:02")
Charvec <- Timedate (Paste (Dates, times))
Timedate (Charvec)
#取系统的时间
Sys.timedate ()
#一个月的第一天
Timefirstdayinmonth ()
#一个月的最后一天
Timelastdayinmonth ()
#一周当中第几天
DayOfWeek ()
#一年当中的第几天
DayOfYear ()

Data analysis in R language (9)--Date and time format 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.