楼主: xucaifeng66
5676 14

[问答] 一变量有很多个list,请问怎么一次性取下 [推广有奖]

  • 0关注
  • 2粉丝

已卖:608份资源

讲师

44%

还不是VIP/贵宾

-

威望
0
论坛币
3633 个
通用积分
26.5666
学术水平
11 点
热心指数
20 点
信用等级
8 点
经验
19481 点
帖子
298
精华
0
在线时间
591 小时
注册时间
2014-5-11
最后登录
2021-1-29

楼主
xucaifeng66 发表于 2015-1-6 09:51:23 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
一个变量有很多个list,通过我要把这些list全部取下来都是用循环。

但是循环比较慢,所以我这不想用循环,那我应该怎么做才能将那些list全取下来呢??

主要是因为,每个list的第一行有我想要的数据,而且我想把那一行的数据全部保存在一个单独的变量中。。

谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:list 一次性 IST 数据全 怎么做 而且

沙发
zngtian 发表于 2015-1-6 09:58:22
用sapply或lapply

藤椅
xucaifeng66 发表于 2015-1-6 10:04:43
zngtian 发表于 2015-1-6 09:58
用sapply或lapply
试了几次,没试出来

板凳
xucaifeng66 发表于 2015-1-6 10:05:24
zngtian 发表于 2015-1-6 09:58
用sapply或lapply
求指点

报纸
李会超 发表于 2015-1-6 10:47:22
  1. > a<-list(x=1:3,y=6:7)
  2. > a
  3. $x
  4. [1] 1 2 3

  5. $y
  6. [1] 6 7

  7. > sapply(a,function(x) x[[1]])
  8. x y
  9. 1 6
  10. >
复制代码
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
xucaifeng66 + 5 + 2 + 2 精彩帖子

总评分: 论坛币 + 5  学术水平 + 2  热心指数 + 2   查看全部评分

地板
xucaifeng66 发表于 2015-1-6 11:00:54
李会超 发表于 2015-1-6 10:47
非常感谢,也有人给我提供了这个  sapply(a, '[', 1),这我还是第一次接触的,不过也很好用

哈哈,谢谢

7
zngtian 发表于 2015-1-6 11:01:26
李会超 发表于 2015-1-6 10:47

The first argument of lapply or sapply should b a list object, and the second argument be either the name of of a built-in function not quoted, like sum, or a self-defined function like the one given above by 李会超. It can also contain additional arguments depending on the function you are using. Sapply or lapply basically loops over each element in a list and applies the function on each of them. They are presumably quicker than using a loop directly.

8
zngtian 发表于 2015-1-6 11:10:05
xucaifeng66 发表于 2015-1-6 11:00
非常感谢,也有人给我提供了这个  sapply(a, '[', 1),这我还是第一次接触的,不过也很好用

哈哈,谢谢 ...
"["(x, 1)和x[1]是一样的。"["()就是定义[ ]的函数。

9
曲散人终 发表于 2015-1-6 11:13:58
They are presumably quicker than using a loop directly...just presumably...

10
zngtian 发表于 2015-1-6 11:16:27
曲散人终 发表于 2015-1-6 11:13
They are presumably quicker than using a loop directly...just presumably...
Yes, presumably. Look at the example in Data Manipulation with R by Phil Spector. Basically, sapply just does some vectorization in the operations, not all vectorized.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-23 13:11