R language Combat-basic data Management (2)

Source: Internet
Author: User

Tag: Cal sys char date conversion ring width std es2017 log

5. Missing values

> y <-C (1,2,3,na) > Is.na (y) [1] false false true> leadership Manager testdate Country Gender age Item1      Item2 item3 item4 item51 1 10/24/08 US M 5 4 5 5 2 10/28/08 US      F 3 5 2 5 3 10/1/08 UK F 25 3 5 5 5 24 4 10/12/08 UK M 3 3 4 na NA5 5 5/1/09 UK F NA 2 2 1 2 1 Strin           Gasfactors agecat1 false Young2 false Young3 false Young4 false Young5     FALSE <NA>> leadership[,6:10] item1 item2 item3 item4 item51 5 4 5 5 52 3 5 2 5 3 5 5 5 3 3 4 NA NA5 2 2 1 2 1> is.na (lead ERSHIP[,6:10]) item1 item2 item3 Item4 item51 false false False FALSE2 false false FALSE3 false F Alse false FALSE4 FalseFalse false TRUE TRUE5 false False false>  

5.1 Re-encoding some values as missing values

5.2 Excluding missing values in analysis

> x <-C (1,2,na,3) > y <-x[1] + x[2] + x[3] + x[4]> z <-sum (x) > X[1] 1 2 NA 3> y[1] na> z[1  ] na> > > x <-C (1,2,na,3) > y <-sum (x, na.rm=true) > > xerror:object ' x ' not found> x[1] 1 2      NA 3> Y[1] 6> leadership manager testdate Country Gender age item1 item2 item3 item4 item51 1 10/24/08  US M 5 4 5 5 2 10/28/08 US F 45 3 5 2 5 53 3 10/1/08 UK F 3 5 5 5 4 10/12/08 UK M (3 3 4 NA N           A5 5 5/1/09 UK F NA 2 2 1 2 1 stringasfactors agecat1 FALSE Young2 False Young3 false Young4 false Young5 false <NA>> NewData <-na.omit      (leadership) > NewData Manager testdate Country Gender age item1 item2 item3 item4 item51 1 10/24/08 US M 32 5 4 5     5 2 10/28/08 US F 3 5 2 5 3 10/1/08 UK F 25 3 5 5 5 2 Stringasfactors agecat1 false Young2 false Young3 false YOUNG&G  T

6. Date value

> Mydates <-as. Date (C ("2007-06-22", "2004-02-13")) > Mydates[1] "2007-06-22" "2004-02-13" > > > Strdates <-C ("01/05/1965 "," 08/16/1975 ") > Strdates[1]" 01/05/1965 "" 08/16/1975 "> Dates <-as. Date (Strdates, "%m/%d/%y") > Dates[1] "1965-01-05" "1975-08-16" > > MyFormat <-"%m/%d/%y" > leadership$ Date <-as. Date (Leadership$date, MyFormat) Error in as. Date.default (Leadership$date, MyFormat): Don't know how to convert ' leadership$date ' to class ' Date ' > Leadership$te Stdate <-as. Date (Leadership$date, MyFormat) Error in as. Date.default (Leadership$date, MyFormat): Don't know how to convert ' leadership$date ' to class ' Date ' > Leadership$te Stdate <-as. Date (Leadership$testdate, MyFormat) > Leadership$testdate[1] "2008-10-24" "2008-10-28" "2008-10-01" "2008-10-12" " 2009-05-01 "> Leadership Manager TestDate Country Gender age item1 item2 item3 item4 item51 1 2008-10-24 U S M 32 5 4 5 5 52 2 2008-10-28 US F 3 5 2 5 3 2008-10-01 UK F 25 3 5 5     5 4 2008-10-12 UK M 3 3 4 na NA5 5 2009-05-01 uk F na 2           2 1 2 1 Stringasfactors agecat1 false Young2 false Young3 false Young4  False Young5 false <NA>> > Sys.date () [1] "2017-09-07" > Date () [1] "Thu Sep 07 22:40:04 "> Today <-sys.date () > Format (today, format="%B%d%Y ") [1]" September "> Format (Today, format="%A ") [1]" Thursday "> > > StartDate <-as. Date ("2004-02-13") > EndDate <-as. Date ("2011-01-22") > Days <-enddate-startdate> daystime difference of 2535 days> > > Today <-SYS.D Ate () > Dob <-as. Date ("1988-06-30") > Difftime (Today, DOB, units= "weeks") time difference of 1523 weeks> difftime (today, DOB, units= " Days ") time difference of 10661 days> Format (DOB, format= "%A") [1] "Thursday" > Format (AS. Date ("2017-09-07"), format= "%A") [1] "Thursday" > Format (AS.  Date ("2017-09-06"), format= "%A") [1] "Wednesday" >

6.1 Converting a date to a character variable

6.2 Further

Help (AS. Date) Help (Strftime) help (isodatetime) lubridate Package Fcalendar Package

7. Type Conversion

R language Combat-basic data Management (2)

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.