Re: [R] how to use by function

2012-06-19 Thread arun
inal Message - From: cowboy To: r-help@r-project.org Cc: Sent: Monday, June 18, 2012 11:32 PM Subject: [R] how to use by function hi all, Assume I have data like data<-rbind(c(1,2),c(1,3),c(2,1),c(3,2),c(3,4)) I want to get some matrix like 1,2,3 2,NA,NA 3,2,4 I'm using by mat<-matrix(

Re: [R] how to use by function

2012-06-19 Thread Rui Barradas
Hello, Your code is not working because you are not understanding what's written in the help page for 'by'. 'by' breaks its first argument, a data.frame, (could be matrix) into sets of rows using 'index' to do the breaking. Each set of rows is the argument for FUN, a function that already ex

[R] how to use by function

2012-06-18 Thread cowboy
hi all, Assume I have data like data<-rbind(c(1,2),c(1,3),c(2,1),c(3,2),c(3,4)) I want to get some matrix like 1,2,3 2,NA,NA 3,2,4 I'm using by mat<-matrix(NA,3,3) by(data,data[,1],mat[data[,1],]<-c(data[,2])) but it doesn't work. Any ideas? thanks, cowboy _

Re: [R] how to use by() ?

2010-11-29 Thread Jim Moon
Jim Moon ohsu.edu> writes: > How might one accomplish this using the by() function? > m1 is a data frame. > > # populate column "m1$major_allele" > for ( i in 1:length(m1$major_allele)) { > if ( m1$Freq1[i] == m1$MAF[i]){ > m1$major_allele[i] = m1$Al1[i] > } > else{ > m1$major_alle

Re: [R] how to use by() ?

2010-11-29 Thread Bert Gunter
... or slightly less verbose: m1 <- within(m1,major_allele <- ifelse( Freq1 == MAF, Al1, Al2 )) ?within Cheers, Bert On Mon, Nov 29, 2010 at 10:25 AM, Greg Johnson wrote: > Jim Moon ohsu.edu> writes: > >> How might one accomplish this using the by() function? >> m1 is a data frame. >> >> #

Re: [R] how to use by() ?

2010-11-29 Thread Greg Johnson
Jim Moon ohsu.edu> writes: > How might one accomplish this using the by() function? > m1 is a data frame. > > # populate column "m1$major_allele" > for ( i in 1:length(m1$major_allele)) { > if ( m1$Freq1[i] == m1$MAF[i]){ > m1$major_allele[i] = m1$Al1[i] > } > else{ > m1$major_all

[R] how to use by() ?

2010-11-29 Thread Jim Moon
Hello, All! How might one accomplish this using the by() function? m1 is a data frame. # populate column "m1$major_allele" for ( i in 1:length(m1$major_allele)) { if ( m1$Freq1[i] == m1$MAF[i]){ m1$major_allele[i] = m1$Al1[i] } else{ m1$major_allele[i] = m1$Al2[i] } } Jim