[R] Help: ifelse selection for x,y coordinates

Céline Lüscher c-luescher at hispeed.ch
Thu Jun 22 10:48:36 CEST 2017


Hi everyone,
My database has 3 columns : the x coordinates, the y coordinates and the value of G for every individual (20 in total). I would like to have the x,y coordinates of individuals, Under these conditions : the distance to the reference coordinates must be under or equal to 50 meters + the value of G must be bigger or equal to 16.

Here’s what I’ve done first :

> kk<- function(x, y) 
+ { 
+   coordx<-data$x.Koordinate[data$G==24]
+   coordy<-data$y.Koordinate[data$G==24]
+   x <- ifelse(data$x.Koordinate>coordx-51 & data$G>15,data$x.Koordinate,0)
+   y<-ifelse(data$y.Koordinate>coordy-51 & data$G>15,data$y.Koordinate,0)
+   return(c(x,y))
+ }
> kk(data$x.Koordinate, data$y.Koordinate)
 [1]      0      0      0      0      0 205550 205550      0 205600 205600      0      0      0      0      0      0      0
[18] 604100      0 604150 604100      0

The problem here is that we can not clearly see the difference between the coordinates for x and the ones for y.

Then I tried this :
> kk<- function(x, y) 
+ { 
+   coordx<-data$x.Koordinate[data$G==24]
+   coordy<-data$y.Koordinate[data$G==24]
+   x <- ifelse(data$x.Koordinate>coordx-51 & data$G>15,data$x.Koordinate," ")
+   y<-ifelse(data$y.Koordinate>coordy-51 & data$G>15,data$y.Koordinate," ")
+   return(list(x,y))
+ }
> kk(data$x.Koordinate, data$y.Koordinate)
[[1]]
 [1] " "      " "      " "      " "      " "      "205550" "205550" " "      "205600" "205600" " "     
 
[[2]]
 [1] " "      " "      " "      " "      " "      " "      "604100" " "      "604150" "604100" " "     
 
>

Where we can see better the two levels related to the x and y coordinates. 

My question is simple : Is it possible for this function to return the values in a form like x,y or x y ? (without any 0, or « », or space) Or should I use another R function to obtain this result ?

Thank you for your help, and sorry for the English mistakes,
C.


Gesendet von Mail für Windows 10


	[[alternative HTML version deleted]]



More information about the R-help mailing list