如何使用逻辑运算符从 R 中的向量中选择值?
问题描述:
我有一个时间位移向量:
I have a vector of time displacement:
time_displ
我只想选择大于 20 的值.
And I want to select only the values which are greater than 20.
我用过这个:twentyuplogical <- time_displ[1:10] >20
但它给了我一个 TRUES 和 FALSE 的向量.
But it gives me a vector of TRUES and FALSE.
如何制作只有大于 20 的值的子集
How can i make a subset with only the values with > 20
答
time_displ_new <- time_displ[time_displ>20]
或
time_displ_new <- subset(time_displ, time_displ>20)
要么会给你一个新的向量,只包含 >20 的值.
Either will give you a new vector containing only the values which are >20.