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 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> 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 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]]
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]]
Hi Peter?! Thanks for your answer?! Indeed it is really better without the empty rows. Unfortunately I did?nt archieve to do it with your propositions, but with this one?:> 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,NA) + y<-ifelse(data$y.Koordinate>coordy-51 & data$G>15,data$y.Koordinate,NA) + xy<-as.data.frame(list(x,y)) + names(xy)<-c("x","y") + return(xy) + }> kk1<-kk(x.Koordinate, y.Koordinate, data=data) > kk1<-kk1[rowSums(is.na(kk1)) != ncol(kk1),] > kk1x y 6 205550 NA 7 205550 604100 9 205600 604150 10 205600 604100 Now it looks great?? Regards, C. Gesendet von Mail f?r Windows 10 Von: Anthoni, Peter (IMK) Gesendet: vendredi, 23 juin 2017 07:39 An: C?line L?scher Cc: r-help at r-project.org Betreff: Re: [R] Help: ifelse selection for x,y coordinates 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> 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 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> 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 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?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]]
Apparently Analagous Threads
- Help: ifelse selection for x,y coordinates
- Help: ifelse selection for x,y coordinates
- Help: ifelse selection for x,y coordinates
- comparition of occurrence of multiple variables between two dataframes
- comparition of occurrence of multiple variables between two dataframes