保持行小于大于 R 中的实数
Keeping the rows with less than bigger than a real number in R
我有一个大数据集,变量包括不同的格式
例如 2, 3, >2, <4, “我去 <> 上学”。 “我需要<在那儿”。
如何创建仅包含 < 2 或 > 10(小于或大于数字)等行的数据集子集?
Subject Result
1 3
2 4
3 <4
4 <3
5 I need to go to school<>
6 I need to <> be there
7 2.3 need to be< there
df[grep("^\s*[<>][0-9]+$", df$variable),]
这将生成 df
的一个子集,其中所有行的数据在列 variable
中的数据格式为前面带有 < 或 > 的数字,后面只有数字。
我添加了 \s*
,因为从您的数据看来,某些情况下数字前有填充空格,因此这将删除任何此类空格。
我有一个大数据集,变量包括不同的格式 例如 2, 3, >2, <4, “我去 <> 上学”。 “我需要<在那儿”。
如何创建仅包含 < 2 或 > 10(小于或大于数字)等行的数据集子集?
Subject Result
1 3
2 4
3 <4
4 <3
5 I need to go to school<>
6 I need to <> be there
7 2.3 need to be< there
df[grep("^\s*[<>][0-9]+$", df$variable),]
这将生成 df
的一个子集,其中所有行的数据在列 variable
中的数据格式为前面带有 < 或 > 的数字,后面只有数字。
我添加了 \s*
,因为从您的数据看来,某些情况下数字前有填充空格,因此这将删除任何此类空格。