which is part of base R so look again. On 6/24/06, Bart Joosen <[EMAIL PROTECTED]> wrote: > Thanks, couldn't find this function, > > Best regards > > Bart > > ----- Original Message ----- > From: "Gabor Grothendieck" <[EMAIL PROTECTED]> > To: "Bart Joosen" <[EMAIL PROTECTED]> > Cc: <[email protected]> > Sent: Saturday, June 24, 2006 1:15 PM > Subject: Re: [R] data frame search > > > > Try this: > > > > which(DF1 == 4, arr.ind = TRUE) > > > > > > On 6/24/06, Bart Joosen <[EMAIL PROTECTED]> wrote: > >> Hi, > >> > >> I want to make a data frame which contains the positions of some searched > >> values in another data frame. > >> > >> Like: > >> Dataframe 1: > >> > >> 1 2 3 4 1 2 3 4 > >> 2 3 4 1 2 3 4 2 > >> 4 1 2 3 2 3 4 1 > >> > >> Let's say I searched on "4", then Dataframe 2 should contain: > >> x y > >> 1 4 > >> 1 8 > >> 2 3 > >> 2 7 > >> 3 1 > >> 3 7 > >> > >> I have written a routine, but it seems to me that it isn't that perfect: > >> x<- 0 > >> > >> y<- 0 > >> > >> for (j in 1:ncol(df)) { > >> > >> for (i in 1:nrow(df)) { > >> > >> if (df[i,j] == 3) { > >> > >> x <- c(x,i) > >> > >> y <- c(y,j) > >> > >> } > >> > >> } > >> > >> } > >> > >> df2 <- data.frame(x,y) > >> > >> df2 <- df2[-1,] > >> > >> Can someone come up with an elegant/faster solution, because the ultimate > >> goal of this routine is to analyze an jpg image. > >> > >> Kind regards > >> > >> Bart > > >
______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
