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)