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-luesc...@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@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. ______________________________________________ R-help@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.