Skip to content

Instantly share code, notes, and snippets.

@sjewo
Created February 13, 2013 18:50
Show Gist options
  • Save sjewo/4947077 to your computer and use it in GitHub Desktop.
Save sjewo/4947077 to your computer and use it in GitHub Desktop.
R-Funktion um zwei Vektoren zeilenweise zusammenzufassen (http://stackoverflow.com/a/12512327)
# 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