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

Anthoni, Peter (IMK) peter.anthoni at kit.edu
Fri Jun 23 07:38:48 CEST 2017


Hi Celine,

what about removing the unwanted after you made the x and y
x<-x[x>0]  # or x<-x[x>0&&y>0], ditto for y, x[x!=""] in your ifelse (... ,"") case

if x and y will not have the same length afterwards you need to make that list thingy.

cheers
Peter



On 23. Jun 2017, at 07:30, Céline Lüscher <c-luescher at hispeed.ch<mailto:c-luescher at hispeed.ch>> wrote:

Hi Jim,

Thank you very much for the answer ! The result is really better with this 😊

Here is the code :
kk<- function(x.Koordinate, y.Koordinate, data=data)
+ {
+   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," ")
+   xy<-as.data.frame(list(x,y))
+   names(xy)<-c("x","y")
+   return(xy)
+ }
kk(x.Koordinate, y.Koordinate, data=data)
       x      y
1
2
3
4
5
6  205550
7  205550 604100
8
9  205600 604150
10 205600 604100

Best regards,
C.


Gesendet von Mail für Windows 10

Von: Jim Lemon
Gesendet: vendredi, 23 juin 2017 05:28
An: Céline Lüscher
Cc: r-help at r-project.org<mailto:r-help at r-project.org>
Betreff: Re: [R] Help: ifelse selection for x,y coordinates

Hi Celine,
Perhaps if you modify your return value like this:

xy<-as.data.frame(list(x,y))
names(xy)<-c("x","y")
return(xy)

Jim

On Thu, Jun 22, 2017 at 6:48 PM, Céline Lüscher <c-luescher at hispeed.ch<mailto:c-luescher at hispeed.ch>> wrote:
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]]

______________________________________________
R-help at r-project.org<mailto:R-help at r-project.org> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org<mailto:R-help at r-project.org> mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.


	[[alternative HTML version deleted]]



More information about the R-help mailing list