Filter function dplyr seems to be not working [closed]

拈花ヽ惹草 提交于 2021-02-05 11:12:49

问题


Let's presume I have a data.fram called exprCore1 loaded in R-Studio, the df looks like this:

   measure qid value
1   p5      1   0.2
2   p100    1   0.8
3   map     1   0.22
4   p5      2   0.4
5   p100    2   0.5
6   map     2   0.32

Basically all want is every column in which the measurement method is "map".

I tried different approaches, all of them just return only a 0x4 tibble without content.

What I tried so far:

library("dplyr", lib.loc="~/R/win-library/3.4")
exprCore1MapOverall <- dplyr::filter(exprCore1, measure == "map")

This just returns:

# A tibble: 0 x 4
# ... with 4 variables: measure <chr>, queryID <chr>, value <dbl>, coreTag <chr>

What am I missing here? Can anyone help me?

Thank you

Edit:

Also tried

exprCore1MapOverall <-filter(exprCore1, measure %in%c("map"))

Edit2:

I cant post the whole data.frame, way to much data. I shrunk it using

exprCore1Fixed <- exprCore1[-c(30: 142082),]

Here is the dput of exprCore1Fixed

structure(list(measure = c("num_ret        ", "num_rel        ", 
"num_rel_ret    ", "map            ", "R-prec         ", "bpref          ", 
"recip_rank     ", "ircl_prn.0.00  ", "ircl_prn.0.10  ", "ircl_prn.0.20  ", 
"ircl_prn.0.30  ", "ircl_prn.0.40  ", "ircl_prn.0.50  ", "ircl_prn.0.60  ", 
"ircl_prn.0.70  ", "ircl_prn.0.80  ", "ircl_prn.0.90  ", "ircl_prn.1.00  ", 
"P5             ", "P10            ", "P15            ", "P20            ", 
"P30            ", "P100           ", "P200           ", "P500           ", 
"P1000          ", "num_ret        ", "num_rel        ", "ircl_prn.0.70  ", 
"ircl_prn.0.80  ", "ircl_prn.0.90  ", "ircl_prn.1.00  ", "P5             ", 
"P10            ", "P15            ", "P20            ", "P30            ", 
"P100           ", "P200           ", "P500           ", "P1000          "
), queryID = c("1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
"1", "1", "1", "1", "2", "2", "all", "all", "all", "all", "all", 
"all", "all", "all", "all", "all", "all", "all", "all"), value = c(752, 
5, 4, 0.1089, 0.2, 0.8, 0.25, 0.25, 0.25, 0.25, 0.1429, 0.1429, 
0.1429, 0.1429, 0.0342, 0.0342, 0, 0, 0.2, 0.1, 0.0667, 0.1, 
0.1, 0.03, 0.02, 0.008, 0.004, 2, 3, 0.0696, 0.0565, 0.0374, 
0.0345, 0.25, 0.1962, 0.1718, 0.151, 0.1192, 0.0525, 0.0335, 
0.0164, 0.0097), coreTag = c("Core_1", "Core_1", "Core_1", "Core_1", 
"Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", 
"Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", 
"Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", 
"Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", 
"Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", "Core_1", 
"Core_1", "Core_1", "Core_1")), .Names = c("measure", "queryID", 
"value", "coreTag"), row.names = c(NA, -42L), class = c("tbl_df", 
"tbl", "data.frame"))

回答1:


Using

dplyr::filter(exprCore1, trimws(measure) == "map")

did the trick, thank you very much.



来源:https://stackoverflow.com/questions/46437300/filter-function-dplyr-seems-to-be-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!