Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
datautils
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bioinfo
datautils
Commits
a0fbd037
Commit
a0fbd037
authored
Nov 14, 2016
by
Holger Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added dataframe search functions.
parent
e2a1df7e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
R/core_commons.R
R/core_commons.R
+19
-0
No files found.
R/core_commons.R
View file @
a0fbd037
...
...
@@ -262,8 +262,27 @@ replaceNA <- function(x, withValue) { x[is.na(x)] <- withValue; x }
## see http://stackoverflow.com/questions/17288222/r-find-value-in-multiple-data-frame-columns/40586572#40586572
## case-insenstive search all columns of a data-frame with a fixed search term
search_df
=
function
(
df
,
search_term
){
apply
(
df
,
1
,
function
(
r
){
any
(
str_detect
(
as.character
(
r
),
fixed
(
search_term
,
ignore_case
=
T
)))
})
%>%
subset
(
df
,
.
)
}
## filter a data-frame for those rows where at least one column is matching the given expression (that must evaluate to a boolean vector for each row).
match_df
=
function
(
df
,
search_expr
){
filter_fun
=
eval
(
substitute
(
function
(
x
){
search_expr
}))
apply
(
df
,
1
,
function
(
r
)
any
(
filter_fun
(
r
)))
%>%
subset
(
df
,
.
)
}
## todo still needed since there's if_else in dplyr now
safe_ifelse
<-
function
(
cond
,
yes
,
no
)
{
warning
(
"DEPRECATED Use dplyr::if_else instead"
)
#browser()
isfacOrChar
<-
function
(
x
)
class
(
x
)
%in%
c
(
"factor"
,
"character"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment