你提的問題不夠詳細,正是你想做的事知道。
一般來說,apply
家庭是非常有用的與載體的工作:看到?apply
文檔如果從要僅保留> 200
向量的那些元素的數字載體列表那麼你可以使用下面的代碼:
# list of numeric vectors
my_list <- list(a = c(201, 199, 202),
b = c(9, 203, 188),
c = c(203, 210, 7))
# using the apply family to e.g. calculate a mean
sapply(my_list, mean)
# a b c
# 200.6667 133.3333 140.0000
# same thing but now with explicitely naming the vector i
# using an anonymous function
sapply(my_list, function(i) mean(i))
# a b c
# 200.6667 133.3333 140.0000
# using a anonymous function to select in the vector what we want
sapply(my_list, function(i){ i[i>200] })
# $a
# [1] 201 202
#
# $b
# [1] 203
#
# $c
# [1] 203 210
請讓我知道這是否是你想要的
你能提供什麼你在'list'?警告基本上告訴你,如果'i'具有比1長的向量,那麼只有第一個元素會被使用。這基本上意味着'list'的結構有問題。你可以很容易地使用'l < - list(1:2); (i> l)if(i> 200)print(i)' –
將'str(list)'的輸出添加到你的問題中應該會有所幫助。 – Marius