R如何提取列表中每个矩阵的第一行? [英] R How do I extract first row of each matrix within a list?

查看:115
本文介绍了R如何提取列表中每个矩阵的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个名为mylist_1的列表,其中包含2个矩阵:

Say I have a list called mylist_1 with 2 matrices:

mylist_1

$region_1           
users   50  20  30
revenue 10000   3500    4000

$red            
users   20  20  60
revenue 5000    4000    10000

如何将每个矩阵的第一行提取到自己的矩阵中?

How do I extract the first row of each matrix into its own matrix?

即输出(第一列是行名):

i.e. output (first column here are rownames):

region_1    50  20  30
region_2    20  20  60

还是每个矩阵的第二行?

or the second row of each matrix?

region_1    10000   3500    4000
region_2    5000    4000    10000

有没有办法引用列表/矩阵来做到这一点?

Is there a way to reference the list/matrices to do this?

谢谢

推荐答案

或者,

lapply(mylist_1, `[`,1,)
lapply(mylist_1, `[`,2,)

这篇关于R如何提取列表中每个矩阵的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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