R基本数据管理(学习笔记)

对于数据的管理,有一些我的的理解,再次申明,这只是我我的的学习笔记,不喜勿喷.python

一、变量的重编码:函数

solution one:学习

相似于python的列表表达式,其增强版为within(),在使用这种方法的时候,千万要注意语句的执行顺序,这个对最终的结果影响很大编码

example:code

对于women这个dataframe,orm

data<-womenthree

data<-within(data,
+ {
+ level<-"low"
+ level[height<60]<-"mid"
+ level[height<70]<-"normal"
+ level[height>=70]<-"high"
+ })

it

这种写法是不行的,缘由是:后一个赋值会覆盖掉前面的赋值: level[height<70]<-"normal"会覆盖掉 level[height<60]<-"mid"(小于60的必然会小于70)io

这样, level[height<60]<-"mid"就不会起做用。变量

solution two:

使用car包的recode()函数
solution three:
使用doBy的recodevar()函数
solution four:
使用自带的函数cut()
相关文章
相关标签/搜索