我有一個數據集,其中一列應該是數值,但有些行的值包含關係運算符,如'> ='或'< ='。爲了簡化這一點,考慮我有一個向量:如何將包含關係運算符的字符串向量轉換爲間隔向量?
a <- c('>= 0.99', '0.66', '<= 0.01')
我應該如何將它轉換爲像間隔的數值向量:
library(intervals)
b <- Intervals(cbind(left = c(0.99, 0.66, -Inf), right = c(Inf, 0.66, 0.01)))
b
# Object of class Intervals
# 3 intervals over R:
# [0.99, Inf]
# [0.66, 0.66]
# [-Inf, 0.01]
您的預期產出是多少? – Uwe
它不會保留任何額外的非數字字符和數字 – akrun
請編輯您的問題,並在Q中添加預期的輸出,而不是在評論中。謝謝。 – Uwe