在多个函数上使用lapply [英] Using lapply on multiple functions

查看:53
本文介绍了在多个函数上使用lapply的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HierCluster 是数据帧的列表.

我可以像这样获得有关一个​​集群的信息:

I can get the info about one cluster like this:

tail(sort(colMeans(HierCluster[[i]])))

其中 i 是列表中的第i个元素.

where i is an i-th element in the list.

我用lapply一次获取了所有集群的信息:

I used lapply to get the info on all the clusters at once:

lapply(lapply(lapply(HierCluster, colMeans), sort), tail)

但是使用lapply 3次似乎很麻烦,有没有更实际的方法呢?

But using lapply 3 times seems rather cumbersome, is there a more practical way of doing this?

推荐答案

您可以创建一个将这三个功能结合在一起的匿名函数:

You can make an anonymous function that combines the three:

lapply(HierCluster, function(x) tail(sort(colMeans(x))))

这篇关于在多个函数上使用lapply的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆