R Language Data operation apply series

Source: Internet
Author: User

1 ################## #R语言中apply类型问题2Data<-data.frame (X=c (1,2,3,4), Y=c (2,3,4,5), Z=c (5,6,7,8))3Apply (Data,2,mean)##apply针对数据框4Lapply (Data,mean)##lapply针对list, of course, it works for Dataframe.5Data1<-list (A=1:10,b=exp ( -3:3), c=C (false,false,false))6Lapply (Data1,mean)##list中每个变量的长度可以是不同的7Sapply (data1,mean,simplify=T)8 #In addition, there is a vapply, there is a parameter fun.value, the results of the return test, if not meet the requirements, will be an error9 #tapplyTenData2<-data.frame (X=c ("F","F","M","M","F"), Y=c (172,176,166,188,190,163)) OneTapply (data2$y,data2$x,mean,simplify=t)##分组统计的功能, simplify is true, returns as a list, FALSE returns the value directly A #aggregate function,,, subtotals - Attach (Mtcars) -Aggregate (Mtcars,by=list (cyl,gear), Fun=mean)

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.