简体   繁体   English

从R中的向量列表中提取值的范围

[英]Extract range of values from a list of vectors in R

I'm struggling with this simple task 我正在为这个简单的任务而苦苦挣扎

I have a list of vectors and I want to extract values in a range, lets say between 1700 and 6200. 我有一个向量列表,我想提取一个范围内的值,可以说介于1700和6200之间。

sample <- list(c(1062, 1084, 1104, 1130, 1143, 1178, 1193, 1209, 1233, 
1276, 1315, 1458, 1752, 2027, 2483, 2598, 2713, 3196, 3780, 4448, 
4937, 5070, 5734, 6347, 6859, 6963), c(1101, 1125, 1153, 1166, 
1201, 1214, 1257, 1281, 1315, 1351, 1493, 1786, 2061, 2514, 2559, 
2583, 2628, 2742, 3185, 3223, 3801, 4469, 4954, 5090, 5753, 6364, 
6874, 6978))

sapply(sample, function(x) x[x > 1700])
sapply(sample, function(x) x[x < 6200])

How to combine theses two functions in one ? 如何将这两个功能合而为一?

sapply(sample, function(x) x[x > 1700] & x[x<6200])

doesn't work, why ? 不起作用,为什么? What am I missing ? 我想念什么?

sapply(sample, function(x) x[x > 1700 & x < 6200])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM