R Basic Data Management (study notes)

Source: Internet
Author: User

For the management of data, there are some personal understanding, again, this is just my personal study notes, do not like to spray.

1. Re-Encoding of variables:

Solution One:

A list expression similar to Python, with the enhanced version of Within (), when using this method, it is important to pay attention to the execution order of the statement, which has a great influence on the final result.

Example

For women this dataframe,

Data<-women

Data<-within (data,
+ {
+ level<-"Low"
+ level[height<60]<-"Mid"
+ level[height<70]<-"Normal"
+ level[height>=70]<-"High"
+ })

This writing is not possible because: the latter assignment overrides the previous assignment: level[height<70]<-"Normal" will overwrite level[height<60]<-"mid" (less than 60 is bound to be less than 70)

In this way, level[height<60]<-"mid" will not work.

Solution:

using the car package's Recode () function Solution Three: use Doby's Recodevar () function Solution Four: use your own function cut ()

R Basic Data Management (study notes)

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.