我有两个名称存储在其中的变量。我想看看变量ScanName
中有多少名字在向量B
中,而忽略了大写字母。另外,有什么区别?
我想忽略搜索中大写字母之间的差异(例如,它应该考虑hsa-mir-1
和hsa-miR-1
相同)。
我的数据是这样的:
str(B)
Factor w/ 1046 levels "hsa-let-7a-1",..: 1 2 3 4 5 6 7 8 9 10 ...
>B
[1] hsa-let-7a-1 hsa-let-7a-2 hsa-let-7a-3 hsa-let-7b hsa-let-7c hsa-let-7d
[7] hsa-let-7e hsa-let-7f-1 hsa-let-7f-2 hsa-let-7g hsa-let-7i hsa-mir-1-1
[13] hsa-miR-1238 hsa-mir-100 hsa-mir-101-1 hsa-mir-101-2 hsa-mir-103-1 hsa-mir-103-1-as
[19] hsa-mir-103-2 hsa-mir-103-2-as hsa-mir-105-1 hsa-mir-105-2 hsa-mir-106a hsa-mir-106b
和
> str(ScanName)
chr [1:1146] "hsa-miR-103b" "hsa-miR-1178" "hsa-miR-1179" "hsa-miR-1180" "hsa-miR-1181
> ScanName
[1] "hsa-miR-103b" "hsa-miR-1178" "hsa-miR-1179" "hsa-miR-1180" "hsa-miR-1181" "hsa-miR-1182"
[7] "hsa-miR-1183" "hsa-miR-1184" "hsa-miR-1193" "hsa-miR-1197" "hsa-miR-1200" "hsa-miR-1203"
[13] "hsa-miR-1204" "hsa-miR-1205" "hsa-miR-1206" "hsa-miR-1208" "hsa-miR-1224-3p" "hsa-miR-1225-3p"
[19] "hsa-miR-1225-5p" "hsa-miR-1227" "hsa-miR-1228" "hsa-miR-1229" "hsa-miR-1231" "hsa-miR-1233"
[25] "hsa-miR-1234" "hsa-let-7a-2" "hsa-miR-1238" "hsa-miR-1243" "hsa-miR-1244" "hsa-miR-1245"
[31] "hsa-miR-1245b-3p" "hsa-miR-1246" "hsa-miR-1247" "hsa-miR-1248" "hsa-miR-1249" "hsa-miR-1250"
[37] "hsa-miR-1251" "hsa-miR-1252"
答案 0 :(得分:3)
你可以使用%in%和tolower
ScanName[tolower(ScanName) %in% tolower(B)]
答案 1 :(得分:1)
您还可以grep
将ignore.case
参数设置为TRUE
> unlist(sapply(B, function(x){
grep(x, ScanName, ignore.case = TRUE, value = TRUE)
}, USE.NAMES = FALSE))
## [1] "hsa-let-7a-2" "hsa-miR-1238"
在
给出相同的结果> ScanName[tolower(ScanName) %in% tolower(B)]
## [1] "hsa-let-7a-2" "hsa-miR-1238"