R language Combat-basic data Management (3)

Source: Internet
Author: User

8. Sorting Data

> leadership$age[1] na> newdata <-leadership[order (leadership$age),]> NewData Manager testDate       Country gender Age Item1 item2 item3 item4 item53 3 2008-10-01 UK F 25 3 5 5 5 21     1 2008-10-24 US M 5 4 5 5 4 2008-10-12 UK m 39 3 3 4     Na NA2 2 2008-10-28 US F 3 5 2 5 5 2009-05-01 UK F NA 2 2 1 2 1 Stringasfactors agecat3 false Young1 false Young4 false you Ng2 false Young5 false <NA>> > > Attach (Leadership) The following objects is masked _by_. Globalenv:age, country, gender, manager> NewData <-Leadership[order (gender, age),]> Detach (Leadership) > N     Ewdata Manager testdate Country Gender age item1 item2 item3 item4 item53 3 2008-10-01 UK F 25 3  5 5 5   2 2008-10-28 US F 3 5 2 5 5 2009-05-01 UK F NA 2      2 1 2 1 2008-10-24 US M + 5 4 5 5 the 4 2008-10-12 UK M 3 3 4 na na stringasfactors agecat3 false Young2 false Young5 FA LSE <na>1 false Young4 false young> > Attach (Leadership) The following objects is mask Ed _by_. Globalenv:age, country, gender, manager> NewData <-leadership[order (Gender,-age),]> Detach (Leadership) >     NewData Manager testdate Country Gender age item1 item2 item3 item4 item55 5 2009-05-01 UK F NA 2      2 1 2 2 2008-10-28 US F 3 5 2 5 (3 2008-10-01 UK) F 3 5 5 5 4 2008-10-12 UK M (3 3 4 NA NA1 1 2008 -10-24 US     M 5 4 5 5 5 Stringasfactors agecat5 false <na>2 false Young3  False Young4 false Young1 false young>

9. Merging data sets

9.1 Adding columns

> Patientid <-C (1, 2, 3, 4) > Age <-C (+,,) > Status <-C ("Poor", "improved", "excellent", "PO or ") > Gender <-C (" F "," M "," M "," F ") > Dataframea <-data.frame (Patientid, gender) > Dataframea Patientid g Ender1 1 F2 2 M3 3 M4 4 f> dataframeb <-data.frame (Patientid, a GE, status) > Dataframeb Patientid age status1 1 Poor2 2 improved3 3 + Excel LENT4 4 poor> Total <-merge (Dataframea, Dataframeb, by= "ID") Error in Fix.by (by.x, X): ' By ' must s Pecify a uniquely valid column> total <-merge (Dataframea, Dataframeb, by= "Patientid") > Total Patientid Gender a      GE Status1 1 F poor2 2 m improved3 3 m EXCELLENT4 4 F-poor> Total <-merge (Dataframea, Dataframeb, By=c ("Gender", "Age")) Error in Fix.by (by.x, X): ' By ' mus T specify a uniquely ValID column> Total <-merge (Dataframea, Dataframeb, By=c ("Patientid", "Age")) Error in Fix.by (by.x, X): ' By ' must spec    Ify a uniquely valid column> > Total <-cbind (Dataframea, DATAFRAMEB) > Total Patientid gender patientid  Status1 1 F 1 Poor2 2 m 2 improved3 3 M 3  EXCELLENT4 4 F 4 poor>

9.2 Adding rows

> Total <-rbind (Dataframea, Dataframeb) Error in Rbind (Deparse.level, ...): Numbers of columns of arguments do   Not match

10. Subset of data sets

10.1 optional (Reserved) variables

10.2 Reject (Discard) variable

10.3 Optional Observations

10.4 Subset () function

10.5 Random Sampling

R language Combat-basic data Management (3)

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.