> With (mtcars,summary (mpg,disp)) Min. 1st Qu. Median Mean 3rd Qu. Max. 10.40 15.42 19.20 20.09 22.80
Equivalent to attach and detach
> mydata=transform (mtcars,sumx=mpg+disp)
Add a new variable to the data frame same as Mydsta$sumx
> View (MyData)
A small box will pop up to view the data
> Within (leadership,{
+ Agecat=na
+ agecat[age>75]= ' Elder '
+ agecat[age<55]= ' young '})
The difference between with and within is that with no modification to the data frame, within can
#对变量的名称进行修改
1) >fix (data) #进行交互式修改
2) reshape package of rename rename (Data,c (oldname= ' newname ', oldname= ' newname '))
3) names (data) [i]= ' NewName '
#移除含有缺失值的观测
1) na.nmit (data)
#日期的输出格式
>format (x,format= '%d%m%y ')
#输出系统日期
>sys.date ()
#计算时间间隔
Difftime (today,anotherday,units= ' weeks ') #返回的为一种特定的类, convert it using as.numeric if needed
#数据排序
> Order (MTCARS$MPG) #返回的为mpg升序排列 (default, if you want to add a symbol before a variable in descending order, or set a parameter) index number
[1] 7, 6, 5, 1, 2, 4, 3, 9, +--ten
So to Mtcars[order (Mtcars$mpg),] only return data
#数据集的合并
>total=merge (dataframea,dataframeb,by= ' id ') is merged #数据依据 ' ID ', equivalent to inner join
The data set contains the judgment of using%in%, which returns a logical vector
#删除变量可以用c (-1) or Var1=null
#依据条件选取观测值
Newdata=subset (Leadership,age>=35,select=c (Q1,Q2))
The form of Newdata=subset (LEADERSHIP,AGE>=35,SELECT=GENDER:Q4) is applied only here to the selection of variables
> mtcars[1:10, ' mpg '] must be double-quoted
#随机抽样
>sample (x, size, replace = FALSE, prob = NULL)
> Sample (1:10,3)
[1] 5 7 3
The "Sqldf" package can be used to use SQL statements
R-Language Review notes-record details