-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arni Magnusson
committed
Mar 27, 2020
1 parent
4eac346
commit aa6551e
Showing
9 changed files
with
306 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
startsWith <- function(str, pattern, trim=FALSE, ignore.case=FALSE) | ||
{ | ||
if(trim) str <- trim(str) | ||
|
||
if(ignore.case) | ||
{ | ||
str <- toupper(str) | ||
pattern <- toupper(pattern) | ||
} | ||
substr(str,start=1,stop=nchar(pattern))==pattern | ||
} | ||
|
||
#substr(str,start=1,stop=nchar(pattern))==pattern | ||
|
||
base::startsWith(str, pattern) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,48 @@ | ||
# This function replace rows in 'x' by corresponding rows in 'y' the have | ||
# the same value for 'by' | ||
update.data.frame <- function(x, y, by, by.x=by, by.y=by, append=TRUE, verbose=TRUE, ...) | ||
{ | ||
retval <- x | ||
x.by <- x[[by.x]] | ||
y.by <- y[[by.y]] | ||
|
||
matches.x <- match(y.by, x.by) | ||
matches.y <- which(!is.na(matches.x)) | ||
nomatch.y <- which(is.na(matches.x)) | ||
matches.x <- matches.x[!is.na(matches.x)] | ||
|
||
if(length(matches.x)>0) | ||
retval[matches.x, ] <- y[matches.y,] | ||
|
||
if(length(nomatch.y) && append) | ||
retval <- rbind(retval, y[nomatch.y,]) | ||
|
||
if(verbose) | ||
{ | ||
cat("\n") | ||
cat("Number of rows in x :", nrow(x), "\n") | ||
cat("Number of rows in y :", nrow(y), "\n") | ||
cat("\n") | ||
cat("Number of rows replaced :", length(matches.x), "\n") | ||
cat("Number of rows appended :", length(nomatch.y), "\n") | ||
cat("\n") | ||
cat("Number of rows in result:", nrow(retval), "\n") | ||
cat("\n") | ||
} | ||
retval | ||
} | ||
# # This function replace rows in 'object' by corresponding rows in 'new' that have | ||
# # the same value for 'by' | ||
# update.data.frame <- function(object, | ||
# new, | ||
# by, | ||
# by.object=by, | ||
# by.new=by, | ||
# append=TRUE, | ||
# verbose=TRUE, | ||
# ...) | ||
# { | ||
# retval <- object | ||
# | ||
# if(length(by.object)>1) | ||
# stop("'by.object' can specify at most one column") | ||
# | ||
# if(length(by.new)>1) | ||
# stop("'by.new' can specify at most one column") | ||
# | ||
# | ||
# object.by <- object[[by.object]] | ||
# new.by <- new [[by.new ]] | ||
# | ||
# matches.object <- match(new.by, object.by) | ||
# matches.new <- which(!is.na(matches.object)) | ||
# nomatch.new <- which(is.na(matches.object)) | ||
# matches.object <- matches.object[!is.na(matches.object)] | ||
# | ||
# if(length(matches.object)>0) | ||
# retval[matches.object, ] <- new[matches.new,] | ||
# | ||
# if(length(nomatch.new) && append) | ||
# retval <- rbind(retval, new[nomatch.new,]) | ||
# | ||
# if(verbose) | ||
# { | ||
# cat("\n") | ||
# cat("Number of rows in object:", nrow(object), "\n") | ||
# cat("Number of rows in new :", nrow(new), "\n") | ||
# cat("\n") | ||
# cat("Number of rows replaced :", length(matches.object), "\n") | ||
# cat("Number of rows appended :", length(nomatch.new), "\n") | ||
# cat("\n") | ||
# cat("Number of rows in result:", nrow(retval), "\n") | ||
# cat("\n") | ||
# } | ||
# retval | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.