Created
February 13, 2013 18:50
-
-
Save sjewo/4947077 to your computer and use it in GitHub Desktop.
R-Funktion um zwei Vektoren zeilenweise zusammenzufassen (http://stackoverflow.com/a/12512327)
This file contains hidden or 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
# Funktion um zwei Vektoren zeilenweise zusammenzufassen | |
# Argumente: | |
# A,B = Vektor | |
# Quelle: http://stackoverflow.com/a/12512327 | |
process <- function(A,B) { | |
x <- cbind(A,B) | |
apply(x,1,function(x) { | |
if(sum(is.na(x))==1) {na.omit(x)} else # ein fehlender Wert | |
if(all(is.na(x))) {NA} else # beide fehlend | |
if(!any(is.na(x))) { # kein fehlender Wert | |
if(x[1]==x[2]) { # -> wenn beide gleich sind, den ersten wert nehmen | |
x[1] | |
} else { | |
-1 # -> ansonsten -1 | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment