Re: [R] Help with apply and new column?

2018-03-05 Thread Sariya, Sanjeev
Thank you, that helps. -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Monday, March 5, 2018 3:36 PM To: Sariya, Sanjeev Cc: r-help@r-project.org; R Help Subject: RE: [R] Help with apply and new column? Comments interspersed, and some code at the end

Re: [R] Help with apply and new column?

2018-03-05 Thread Jeff Newmiller
t;:" ) # gets the whole column splits at once # wildly guessing here rs_chrmatrix <- do.call( rbind, temp ) rs_DF <- as.data.frame( rs_chrmatrix, stringsAsFactors = FALSE ) names( rs_DF ) <- c( "CHR", "P", "X1", "X2" ) rs_DF$P <- as.integer( rs_DF$P ) str( rs_DF ) ##

Re: [R] Help with apply and new column?

2018-03-05 Thread Sariya, Sanjeev
data)<-c("SNP","P","CHR","BP") -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Monday, March 5, 2018 1:48 PM To: r-help@r-project.org; Sariya, Sanjeev ; R Help

Re: [R] Help with apply and new column?

2018-03-05 Thread Jeff Newmiller
Read the Posting Guide... (see message footer) ... some relevant things you can find there: a) Yes, this appears to be about how to use an R base function so it is on topic b) Post a reproducible example (include some sample data, preferably using the dput function) c) Post using plain text so t

Re: [R] help with apply (lapply or sapply not sure)

2013-07-25 Thread PIKAL Petr
Hi I would just use for cycle. Something like lll <- vector("list", length(InputFiles)) for (i in InputFiles) { everything what you want to do for each file you can store it in a list lll[[i]] <- whatever you want to store there } After populating list you can do anything with it. Regards Pet

Re: [R] Help with "apply"

2011-05-12 Thread Berend Hasselman
M.Ribeiro wrote: > > Ok, I am sorry, I was building a reproducible example to post here and I > made a mistake. Th second loop (in the variable k) updates ycorr. > Therefore, it would be > > ycorr <- rnorm(10) > Nindiv <- 10 > x <-matrix(sample(c(0:2),50,re = T),10) > gtemp <- rnorm(10) > for (i

Re: [R] Help with "apply"

2011-05-12 Thread M.Ribeiro
Ok, I am sorry, I was building a reproducible example to post here and I made a mistake. Th second loop (in the variable k) updates ycorr. Therefore, it would be ycorr <- rnorm(10) Nindiv <- 10 x <-matrix(sample(c(0:2),50,re = T),10) gtemp <- rnorm(10) for (i in 1:Nindiv) { for (k in 1:nco

Re: [R] Help with "apply"

2011-05-12 Thread Dennis Murphy
Hi: Are you *sure* that's what you want to do? > y - x[,5] * gtemp[5] [1] 0.10116205 2.46220119 3.04966544 0.56074569 -1.14872521 -0.89275228 [7] 3.52161381 0.64880894 0.70167063 -0.06120996 > identical(as.vector(ycorr), y - x[,5] * gtemp[5]) [1] TRUE Perhaps you ought to explain what y

Re: [R] Help with apply

2010-10-04 Thread Joshua Wiley
keley.edu] > Sent: Monday, October 04, 2010 2:20 PM > To: Doran, Harold > Cc: Gabriela Cendoya; R-help > Subject: Re: [R] Help with apply > > Harold - >    The first way that comes to mind is > > doit = function(i,j)exp(sum(log((exp(tmp[i,]*(qq$nodes[j]-b))) / >        

Re: [R] Help with apply

2010-10-04 Thread Doran, Harold
ld Cc: Gabriela Cendoya; R-help Subject: Re: [R] Help with apply Harold - The first way that comes to mind is doit = function(i,j)exp(sum(log((exp(tmp[i,]*(qq$nodes[j]-b))) / (factorial(tmp[i,]) * exp(exp(qq$nodes[j]-b)) * ((1/(s*sqrt(2*pi))) * exp(-((qq$nodes[j]-0)^2/(

Re: [R] Help with apply

2010-10-04 Thread Phil Spector
PM To: Doran, Harold Cc: R-help Subject: Re: [R] Help with apply You are missing "s" in your definitions so I can't reproduce your code. tmp <- data.frame(var1 = sample(c(0:10), 3, replace = TRUE), var2 = sample(c(0:10), 3, replace = TRUE), var3 = sample(c(0:10), 3, repl

Re: [R] Help with apply

2010-10-04 Thread Joshua Wiley
On Mon, Oct 4, 2010 at 10:44 AM, Gabriela Cendoya wrote: > You are missing "s" in your definitions so I can't reproduce your code. When he uses apply(), he sets s = 1. > >> tmp <- data.frame(var1 = sample(c(0:10), 3, replace = TRUE), var2 = >> sample(c(0:10), 3, replace = TRUE), var3 = sample(c

Re: [R] Help with apply

2010-10-04 Thread Doran, Harold
Sorry about that; s <- 1 -Original Message- From: Gabriela Cendoya [mailto:gabrielacendoya.rl...@gmail.com] Sent: Monday, October 04, 2010 1:44 PM To: Doran, Harold Cc: R-help Subject: Re: [R] Help with apply You are missing "s" in your definitions so I can't reproduce

Re: [R] Help with apply

2010-10-04 Thread Gabriela Cendoya
You are missing "s" in your definitions so I can't reproduce your code. > tmp <- data.frame(var1 = sample(c(0:10), 3, replace = TRUE), var2 = > sample(c(0:10), 3, replace = TRUE), var3 = sample(c(0:10), 3, replace = TRUE)) > > str(tmp) 'data.frame': 3 obs. of 3 variables: $ var1: int 9 3 9

Re: [R] Help with apply()

2010-02-08 Thread Nathan S. Watson-Haigh
On 8/02/2010 4:33 PM, Jim Lemon wrote: On 02/08/2010 12:26 PM, Nathan S. Watson-Haigh wrote: I have a 2 column data.frame: > d[1:5,] a b 1 80015 C 2 80016 B 3 80023 C 4 80062 B 5 80069 B I want to apply a function across each row: > for(i in 1:nrow(d)) { + myFun(con, d[i,]$a, d[i,]

Re: [R] Help with apply()

2010-02-08 Thread Nathan S. Watson-Haigh
On 8/02/2010 2:08 PM, David Winsemius wrote: On Feb 7, 2010, at 8:26 PM, Nathan S. Watson-Haigh wrote: I have a 2 column data.frame: d[1:5,] a b 180015 C 280016 B 380023 C 480062 B 580069 B I want to apply a function across each r

Re: [R] Help with apply()

2010-02-07 Thread Jim Lemon
On 02/08/2010 12:26 PM, Nathan S. Watson-Haigh wrote: I have a 2 column data.frame: > d[1:5,] a b 1 80015 C 2 80016 B 3 80023 C 4 80062 B 5 80069 B I want to apply a function across each row: > for(i in 1:nrow(d)) { + myFun(con, d[i,]$a, d[i,]$b) + } How do I do this using apply()? I'm unsu

Re: [R] Help with apply()

2010-02-07 Thread David Winsemius
On Feb 7, 2010, at 8:26 PM, Nathan S. Watson-Haigh wrote: I have a 2 column data.frame: > d[1:5,] a b 180015 C 280016 B 380023 C 480062 B 580069 B I want to apply a function across each row: > for(i in 1:nrow(d)) { +myFun(con, d[i,]$a, d[i,]$b) +

Re: [R] Help with apply and split...

2008-05-02 Thread Richard . Cotton
> datg=t(sapply(split(datgic, datgic$NPERMNO, drop=TRUE), function(x){return( > x[nrow(x),] )})) > > > I get something like this... > > GVKEY NPERMNO GIC year > 10001 12994 10001 55102010 2007 > 10002 19049 10002 40101015 2007 > 10009 16739 10009 40101010 1999 > > Has this

Re: [R] Help with apply and split...

2008-05-02 Thread jim holtman
What you are seeing are the row numbers of the original locations. If datgic is really a data frame, this is probably what you want using lapply and do.call: > x <- data.frame(a=letters, b=sample(1:4, 26, TRUE)) > y <- lapply(split(x, x$b), tail, 1) > do.call(rbind, y) a b 1 z 1 2 y 2 3 w 3 4 x