[R] For loop

2008-06-27 Thread Rajasekaramya
Hi, Could you please let me know to use a list in a for loop here geneset is a loop.I am trying to match the names of the list with 1st row of the output. result<- list() for(i in 1:length(output) { result[[i]] <- geneset(which(geneset %n% output[,1])) } Kindly help me out -- View t

[R] For loop

2008-07-03 Thread laila khalfan
Hi I have a specific sample coming from a gamma(alpha,theta1) distribution and then divided into two parts first part follows a gamma(alpha,theta1) the second is gamma(alpha,theta2) then I would like to find the mle`s for theta1 and theta2 which I found. Now I would like to simulate those estima

[R] For loop

2008-07-03 Thread laila khalfan
HiI have a specific sample coming from a gamma(alpha,theta1) distribution and then divided into two parts first part follows a gamma(alpha,theta1) the second is gamma(alpha,theta2) then I would like to find the mle`s for theta1 and theta2 which I found. Now I would like to simulate those estimat

[R] 'for Loop'

2009-03-31 Thread Alan O'Loughlin
Hello, I'm trying to create a for loop for a data set, I have a list of results in this data set and I want to take the 1st two add them together and divide by the mean of the 1st to, then do the same for the 3rd and 4th values in the list and so on and each time return a value for the calcul

[R] for loop

2009-05-09 Thread aledanda
Hi, I need your help. I have a vector of numbers reflecting the switch in the perception of a figure. For a certain period I have positive numbers (which reflect the perception A) then the perception changes and I have negative numbers (perception B), and so on for 4 iterations. I need to take

[R] for loop

2009-08-05 Thread waltzmiester
I am trying to get the function "Models" to work each time there is an instance of k. This code will stop after the first model is complete. I need it to come back and pass the next value of c into the "Initial.State" function. any ideas? col<-c(23:28) #Setup for(k in col){ Initial.State(Respon

Re: [R] For loop

2008-06-28 Thread ctu
Hi, I guess this what your need. I assume your output is 10 by 11 matrix. However, you still need to define your geneset function(?) result<- list() output<-matrix(NA, nrow=10, ncol=11) for(i in 1:length(ncol(output))) { result[[i]] <- geneset(which(geneset %n% output[1,])) } Chunha

[R] For Loop performance

2008-01-13 Thread My Coyne
Hello, Newbie question and hope you can help . I have two vector V1 and V2, where length(V2) = length of (V1) * 2; length(V1) ~ 16,000. For each member in V1, I need to compare 2 element of V2 for equality i.e. for (I in 1:length (V1)) { if ( v2[i] == v1[i] & v2[i+1]==v1[i] ){

[R] for loop help

2008-01-29 Thread Adriana Bejarano
Hi, I have written the following code which works fine step<-5 numSim<-15 N<-double(numSim) A<-double(numSim) F<-double(numSim) M<-double(numSim) genx<-double(numSim) for (i in 1:numSim) { N[i]<-20 PN<-(runif(N[i], 0, 1)) A[i]<-sum(ifelse(PN>0.2, 1, 0)) PF<- runif((A[i]*0.5

[R] for loop help

2008-04-10 Thread tom soyer
Hi, I am trying to find a solution in R for the following C++ code that allows one to skip ahead in the loop: for (x = 0; x <= 13; x++){ x=12; cout << "Hello World"; } Note that "Hello World" was printed only twice using this C++ loop. I tried to do the same in R: for(i in 1:13){ i=12 print

[R] for loop step

2008-05-20 Thread Nair, Murlidharan T
How do I define the incremental step in a "for" loop? for (j in 1:10){ cat(j, "\n") } In the above example, if I want to increment j by 2 where do I specify that? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mail

[R] for loop query

2008-12-09 Thread Gerard M. Keogh
Hi all, apologies if this is obvious - but I can't see it and would appreciate some quick help! the matrix mhouse is 26x3 and I'm computing odds ratios. The simple code below "should" compute the odds vector for every pair (325) i.e. 26C2 in cols 1 and 2. On the first i=1 outer loop the inner j

Re: [R] 'for Loop'

2009-03-31 Thread Jun Shen
Al, Is there any "ID" index for the pairs? For example, if the first pair can be labeled "a", and second pair labeled "b" etc., then you can add an index column or you may already have such a column in your list. Then run aggregate(your.data.column, by=index.column, FUN=mean). Or you can just add

Re: [R] 'for Loop'

2009-03-31 Thread Jun Shen
Al, Say, your data file is 'test', execute the following in sequence, aggregate(test[1],test[2],mean)->inter names(inter)[2]='mean' merge(test,inter,all=T)->inter2 inter2$RSV=inter2$Result/inter2$mean The column 'RSV' in inter2 should be what you want. Jun On Tue, Mar 31, 2009 at 11:11 AM, Al

Re: [R] 'for Loop'

2009-03-31 Thread Erich Neuwirth
If you add 2 numbers a and b and divide this sum by the mean of these 2 number, you will always get 2 (a+b)/((a+b)/2) always simplifies to 2. Alan O'Loughlin wrote: > Hello, > > I'm trying to create a for loop for a data set, I have a list of results in > this data set and I want to take the

[R] For Loop Syntax

2009-04-27 Thread Bronagh Grimes
Hi there, Just wondering if someone can help me with the correct syntax to use with for loops? I have split my original file by count, & wish to first of all assign new tables based on the splits. Then I just want to create a new variable. Please see code below. This code works outsid

[R] for loop vectorization

2009-05-07 Thread miraceti
Hi, I am still not familiar with vectorization. Could you help with making this for loop more efficient? The code is trying to make a Q matrix for a multidimensional state space with specific conditions. thanks Mira tmp = 0:(maxvals[1]) for(i in 2:nchars) { tmp <- outer(tmp, 0:(maxvals[i]), FU

Re: [R] for loop

2009-05-09 Thread Uwe Ligges
aledanda wrote: Hi, I need your help. I have a vector of numbers reflecting the switch in the perception of a figure. For a certain period I have positive numbers (which reflect the perception A) then the perception changes and I have negative numbers (perception B), and so on for 4 iterati

Re: [R] for loop

2009-08-05 Thread jim holtman
What do you mean by "stop"? Is there an error message? What are you getting as output? I don't see you saving or printing the output from "Models" (whatever that is). PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, repr

Re: [R] for loop

2009-08-05 Thread Daniel Malter
von waltzmiester Gesendet: Wednesday, August 05, 2009 11:38 AM An: r-help@r-project.org Betreff: [R] for loop I am trying to get the function "Models" to work each time there is an instance of k. This code will stop after the first model is complete. I need it to come back and pass the

Re: [R] for loop

2009-08-05 Thread waltzmiester
Jim Settle down, just because you can't understand my post doesn't mean I didn't follow the guidlines. 1)The code is commented. 2)The problem in the code is succinct and therefore "minimal" even though it cannot be self contained, the user-defined function itself is. 3) In order for you to be ab

Re: [R] for loop

2009-08-05 Thread waltzmiester
The Initial.State function is the setup for Models. So Models will apply the function to k columns in Initial.State. It will only work for the first element in vector col however, and will not loop the function through all elements in vector col -C waltzmiester wrote: > > I am trying to get

Re: [R] for loop

2009-08-05 Thread Daniel Malter
- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von waltzmiester Gesendet: Wednesday, August 05, 2009 1:22 PM An: r-help@r-project.org Betreff: Re: [R] for loop Jim Settle down, just because you can't understand my post doesn't mean I didn't foll

Re: [R] for loop

2009-08-05 Thread Daniel Malter
lto:r-help-boun...@r-project.org] Im Auftrag von waltzmiester Gesendet: Wednesday, August 05, 2009 1:35 PM An: r-help@r-project.org Betreff: Re: [R] for loop The Initial.State function is the setup for Models. So Models will apply the function to k columns in Initial.State. It will only work for th

Re: [R] for loop

2009-08-05 Thread David Winsemius
On Aug 5, 2009, at 1:22 PM, waltzmiester wrote: Jim Settle down, just because you can't understand my post doesn't mean I didn't follow the guidlines. 1)The code is commented. 2)The problem in the code is succinct and therefore "minimal" even though it cannot be self contained, the user

Re: [R] for loop

2009-08-05 Thread waltzmiester
Um I still followed the guidelines... David Winsemius wrote: > > > On Aug 5, 2009, at 1:22 PM, waltzmiester wrote: > >> >> Jim >> >> Settle down, just because you can't understand my post doesn't mean >> I didn't >> follow the guidlines. >> 1)The code is commented. >> 2)The problem in the

Re: [R] for loop

2009-08-05 Thread David Winsemius
You followed only the ones you thought were important, but failed... a) to reduce the problem to a reproducible form (and gave no evidence of even trying to do so.) and failed ... b) to read the helpful reply you got from Jim, which I suspect contained the answer, and now ... c) persist in th

Re: [R] for loop

2009-08-05 Thread Steve Lianoglou
Hi, On Aug 5, 2009, at 2:36 PM, waltzmiester wrote: Um I still followed the guidelines... Focus on trying to ask a better question rather than going down this route ... Honestly, your original question is rather vague and leaves us to guess (i) what you're trying to do, and (ii) how to

Re: [R] for loop

2009-08-05 Thread Daniel Malter
liche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von waltzmiester Gesendet: Wednesday, August 05, 2009 2:37 PM An: r-help@r-project.org Betreff: Re: [R] for loop Um I still followed the guidelines... David Winsemius wrote: > > >

[R] 'for' loop, two variables

2008-07-29 Thread Oehler, Friderike (AGPP)
Dear Rusers, I am still an unexperienced builder of functions and loops, so my question is very basic: Is it possible to introduce a second variable (j) into my loop. To examplify: # This works fine: fn <- function (x) {if (x>46 & x<52) 1 else 0} res <-NULL for (i in 40:60) res <-c(res,fn(i))

Re: [R] For Loop performance

2008-01-13 Thread Uwe Ligges
My Coyne wrote: > Hello, > > > > Newbie question and hope you can help . > > I have two vector V1 and V2, where length(V2) = length of (V1) * 2; > length(V1) ~ 16,000. > > For each member in V1, I need to compare 2 element of V2 for equality If just the comparison is concerned, you can do

Re: [R] For Loop performance

2008-01-13 Thread mcoyne
WRT: Say length(V1) is n, do you want to compare > v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4] > or > v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2] v1[1] with (v2[1] and v2[2]) v1[2] with (v2[3] and v2[4]) v1[3] with (v2[5] and v2[6]) ... v1[n] with (v2[n+1] an

Re: [R] For Loop performance

2008-01-13 Thread Uwe Ligges
[EMAIL PROTECTED] wrote: > WRT: Say length(V1) is n, do you want to compare >> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4] >> or >> v1[1] with v2[1] and v2[n+1] and v1[2] with v2[2] and v2[n+2] > > v1[1] with (v2[1] and v2[2]) > v1[2] with (v2[3] and v2[4]) > v1[3] with (v2[5] and

Re: [R] For Loop performance

2008-01-13 Thread mcoyne
Hi Uwe, Thank you so much for your help. It works great with your suggestion/help. WOW, what a difference! --MyC > > > [EMAIL PROTECTED] wrote: >> WRT: Say length(V1) is n, do you want to compare >>> v1[1] with v2[1] and v2[2] and v1[2] with v2[3] and v2[4] >>> or >>> v1[1] with v2[1] and v2[n

Re: [R] for loop help

2008-01-29 Thread jim holtman
Is this what you want? > numSim <- 15 > > genx<-double(numSim) > N <- rep(20, numSim) > A <- F <- M <- numeric(numSim) > > result <- lapply(1:5, function(.x){ + for (i in 1:numSim) { + PN<-(runif(N[i], 0, 1)) + A[i]<-sum(ifelse(PN>0.2, 1, 0)) + PF<- runif((A[i]*0.5), 0,

Re: [R] for loop help

2008-04-10 Thread Bill.Venables
11 April 2008 12:26 PM To: r-help@r-project.org Subject: [R] for loop help Hi, I am trying to find a solution in R for the following C++ code that allows one to skip ahead in the loop: for (x = 0; x <= 13; x++){ x=12; cout << "Hello World"; } Note that "Hello World" was pri

Re: [R] for loop help

2008-04-10 Thread Hans-Jörg Bibiko
On 11.04.2008, at 05:38, <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote: >> ?`break` >> ?`next` >> > > >> for(i in 1:13) { >> > if(i < 13) next > print("Hello!\n") > } > [1] "Hello!\n" > >> >> > > I am trying to find a solution in R for the following C++ code that > allows > one to s

Re: [R] for loop help

2008-04-11 Thread Greg Snow
Tom, Bill Venables gave you references to important tools for dealing with for loops in R and they may be all the solution that you need. But here is a little more detail on what is going on in case you want/need more control in the future. Note that the R for loop is what some programers call

[R] R for loop question

2008-05-20 Thread Douglas M. Hultstrand
Hello, I am trying to assign a variable name (x1,x2,x3...) in a loop statement that is based on a counter (counter is based on the number of hours within the datafile). The x1,x2 data will later be called for plotting the data. Below is a clip of the for loop I am using, any suggestions? k

Re: [R] for loop step

2008-05-20 Thread Erik Iverson
You are doing it in your bit about 1:10, which is shorthand for generating a sequence 1, 2, 3, ..., 9, 10. Use ?seq to do what you want. for(i in seq(1, 10, by = 2)) cat(i, "\n") Best, Erik Nair, Murlidharan T wrote: How do I define the incremental step in a "for" loop? for (j in 1:10){

Re: [R] for loop query

2008-12-09 Thread Claudia Beleites
Hi, > Why isn't my loop incrementing i - the outer loop to 2 and then resetting > j=3? It is. It runs out of bounds with j > 26 > Am I missing something obvious? > > for (i in 1:25) > + { > + for (j in i+1:26) You miss parentheses. i + 1 : 26 is i + (1 : 26) as the

Re: [R] for loop query

2008-12-09 Thread Robin Hankin
Hi start simple! Work out *each* row combined with *each* row, to give (in your case) a 26-by-26 matrix. Only after you have got this working, start thinking about making it run faster [eg by only evaluating the upper triangular entries] To do a nested loop, do M <- matrix(0,n,n) for(i in

Re: [R] For Loop Syntax

2009-04-27 Thread jim holtman
What do you expect this statement to do: trial[i] <- data.frame(A2$`i`) what is `i` supposed to mean? What is it that you want to do? On Mon, Apr 27, 2009 at 10:25 AM, Bronagh Grimes wrote: > Hi there, > > > > Just wondering if someone can help me with the correct syntax to use > with fo

Re: [R] for loop vectorization

2009-05-07 Thread miraceti
uhoh, missed two lines on the top.Sorry about that. the whole code looks like this. nchars = 4 maxvals = c(2,2,2,2) tmp = 0:(maxvals[1]) for(i in 2:nchars) { tmp <- outer(tmp, 0:(maxvals[i]), FUN="paste", sep=".") } states = tmp stateidx = array(1:length(states), dim=dim(states)) transition <-

Re: [R] for loop vectorization

2009-05-07 Thread miraceti
this 'ifelse' usage looks promising. thank you very much. On Thu, May 7, 2009 at 3:12 PM, Patrick Burns wrote: > If you haven't seen it yet, > 'The R Inferno' may be of use > to you. > > > Patrick Burns > patr...@burns-stat.com > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of "The R I

Re: [R] 'for' loop, two variables

2008-07-29 Thread Duncan Murdoch
On 7/29/2008 7:55 AM, Oehler, Friderike (AGPP) wrote: Dear Rusers, I am still an unexperienced builder of functions and loops, so my question is very basic: Is it possible to introduce a second variable (j) into my loop. To examplify: # This works fine: fn <- function (x) {if (x>46 & x<52) 1 els

Re: [R] 'for' loop, two variables

2008-07-29 Thread ONKELINX, Thierry
ilto:[EMAIL PROTECTED] Namens Oehler, Friderike (AGPP) Verzonden: dinsdag 29 juli 2008 13:56 Aan: Oehler, Friderike (AGPP); r-help@r-project.org Onderwerp: [R] 'for' loop, two variables Dear Rusers, I am still an unexperienced builder of functions and loops, so my question is very basic: I

Re: [R] 'for' loop, two variables

2008-07-29 Thread Benno Pütz
On 29.Jul.2008, at 14:13, ONKELINX, Thierry wrote: Dear Frederike, #Both your functions are vectorized. So you don't need loops. Working with vectorized functions is much faster than looping. fn <- function (x,y) { ifelse(x>46 & x<52 & y<12, 1, 0) } datagrid <- expand.grid(i = 40:60, j = 0

[R] for loop and if problem

2009-01-06 Thread Sake
Hi, I'm heaving difficulties with a dataset containing gene names and positions of those genes. Not such a big problem, but each gene has multiple exons so it's hard to say where de gene starts and where it ends. I want the starting and ending position of each gene in my dataset. Attached is the

[R] for loop in nls function

2008-04-29 Thread Ingrid Tohver
Hello, I am trying to apply a least squares non-linear regression to my dataset, dem16. I can apply it to a subset based on a single site fine, but I want to apply it to each (of 197) sites. I am stumbling over a "for" loop. Site and Mean_Air are variables in my dataset and I would like to

Re: [R] R for loop question

2008-05-20 Thread Erik Iverson
Douglas - To answer your question directly, use perhaps combination of ?assign and ?paste. In general, you usually do not have to do this sort of thing, but can use one of the apply family of functions (apply, sapply, lapply, mapply) to do whatever you want with shorter, cleaner code and few

Re: [R] R for loop question

2008-05-20 Thread Juan Manuel Barreneche
I had to do the same thing many times, i usually use a combination of the functions "eval", "parse" and "sprinf", as below: k <- 1 for (i in 1:length(stats$hour)) { eval(parse(text=sprintf("x%s <- dataset[%s,(3:15)]", i, k))) k <- k+1 } what it does is: eval(parse(text=STRING)) is a way to

Re: [R] R for loop question

2008-05-20 Thread Erik Iverson
Take a look at ?assign Juan Manuel Barreneche wrote: I had to do the same thing many times, i usually use a combination of the functions "eval", "parse" and "sprinf", as below: k <- 1 for (i in 1:length(stats$hour)) { eval(parse(text=sprintf("x%s <- dataset[%s,(3:15)]", i, k))) k <- k+1

Re: [R] R for loop question

2008-05-20 Thread jim holtman
Consider using a 'list' instead of creating a lot of objects that you then have to manage: x <- lapply(1:length(stats$hour), function(.indx) dataset[.indx, 3:15]) You can then access the data as x[[1]], ... On Tue, May 20, 2008 at 12:58 PM, Douglas M. Hultstrand < [EMAIL PROTECTED]> wrote: > He

[R] for loop if else conditional

2007-10-15 Thread Vishal Belsare
date <- as.POSIXlt(Sys.time()) #present date for (i in 1:difftime(as.POSIXlt(Sys.Date()),"2007-10-01")) if (date$wday != 0 & date$wday != 6) {print(date);assign("date", (date-86400))} else (assign("date", (date-86400))) I am trying to print dates from present day to a day

[R] for loop if else conditional

2007-10-15 Thread Vishal Belsare
date <- as.POSIXlt(Sys.time()) #present date for (i in 1:difftime(as.POSIXlt(Sys.Date()),"2007-10-01")) if (date$wday != 0 & date$wday != 6) {print(date);assign("date", (date-86400))} else (assign("date", (date-86400))) I am trying to print dates from present day to a da

[R] for loop if else conditional

2007-10-15 Thread Vishal Belsare
date <- as.POSIXlt(Sys.time()) #present date for (i in 1:difftime(as.POSIXlt(Sys.Date()),"2007-10-01")) if (date$wday != 0 & date$wday != 6) {print(date);assign("date", (date-86400))} else (assign("date", (date-86400))) I am trying to print dates from present day to a day in the

[R] for loop for file names

2009-07-30 Thread waltzmiester
I am trying to load binary files in the following fashion load("pred/Pred_pres_a_indpdt") load("pred/Pred_pres_b_indpdt") load("pred/Pred_pres_c_indpdt") load("pred/Pred_pres_d_indpdt") load("pred/Pred_pres_e_indpdt") load("pred/Pred_pres_f_indpdt") but I would like to set up a for loop to repla

[R] For Loop Iteration: Variable Counter

2009-08-03 Thread Vivek Ayer
Hey guys, How do I iterate such that I add 100 to the counter every time? Suppose: for (i in c(1:100)) I want i to be 1, 10, 20, 30, ... instead of 1,2,3,4,5 ... How can this be done? Thanks, Vivek __ R-help@r-project.org mailing list https://stat.e

[R] For-Loop faster than vectorized code?

2008-01-25 Thread Ralph79
Dear R-Users, I am working on an Hierarchical Bayes model and tried to replace the inner for-loop (which loops over a list with n.observations elements) with truely vectorized code (where I calculated everything based on ONE dataset over all respondents). However, when comparing the performance

Re: [R] for loop and if problem

2009-01-06 Thread Richard . Cotton
> I'm heaving difficulties with a dataset containing gene names and positions > of those genes. > Not such a big problem, but each gene has multiple exons so it's hard to say > where de gene starts and where it ends. I want the starting and ending > position of each gene in my dataset. > Attached

Re: [R] for loop and if problem

2009-01-06 Thread Philipp Pagel
On Tue, Jan 06, 2009 at 07:21:48AM -0800, Sake wrote: > I'm heaving difficulties with a dataset containing gene names and positions > of those genes. > Not such a big problem, but each gene has multiple exons so it's hard to say > where de gene starts and where it ends. I want the starting and endi

Re: [R] for loop and if problem

2009-01-06 Thread Charles C. Berry
On Tue, 6 Jan 2009, Sake wrote: Hi, I'm heaving difficulties with a dataset containing gene names and positions of those genes. Not such a big problem, but each gene has multiple exons so it's hard to say where de gene starts and where it ends. I want the starting and ending position of each g

Re: [R] for loop and if problem

2009-01-07 Thread Sake
Sake wrote: > > Hi, > > I'm heaving difficulties with a dataset containing gene names and > positions of those genes. > Not such a big problem, but each gene has multiple exons so it's hard to > say where de gene starts and where it ends. I want the starting and ending > position of each gene i

Re: [R] for loop and if problem

2009-01-07 Thread Gabor Grothendieck
On Wed, Jan 7, 2009 at 3:51 AM, Sake wrote: > aggregate(data[, c("Exon_Start.Chr.")], by = list(data$Gene), min) > aggregate(data[, c("Exon_Stop.Chr.")], by = list(data$Gene), max) That could be written: aggregate(data["Excon_Start.Chr."], data["Gene"], min) aggregate(data["Excon_Start.Chr."], d

Re: [R] for loop and if problem

2009-01-12 Thread Sake
I have one final question... How can I save a CSV ifile with ; separation in stead of , separation? I know the write.csv(file="filename.csv") an that you can use sep=";" when you open a .csv file, but that doesn't work with the write.csv command. -- View this message in context: http://www.nabbl

Re: [R] for loop and if problem

2009-01-12 Thread jim holtman
Try using: write.table(..., sep=";") write.csv just calls write.table On Mon, Jan 12, 2009 at 6:38 AM, Sake wrote: > > I have one final question... > How can I save a CSV ifile with ; separation in stead of , separation? > I know the write.csv(file="filename.csv") an that you can use sep=";" wh

Re: [R] for loop and if problem

2009-01-12 Thread David Winsemius
write.csv does exactly what you would expect ... creates a *Comma* Separated Values file. If you don't want a comma separated value format then use write.table with sep=";" You can still name it "whatever.csv". Or you if you also intend commas for decimal points, use write.csv2 as describ

Re: [R] for loop and if problem

2009-01-12 Thread Prof Brian Ripley
There is write.csv2 on the same help page as write.csv! 'write.csv' uses '"."' for the decimal point and a comma for the separator. 'write.csv2' uses a comma for the decimal point and a semicolon for the separator, the Excel convention for CSV files in some Western Europ

Re: [R] for loop and if problem

2009-01-13 Thread Sake
Thanks! Why did I not think at that myself. .csv means 'Comma Separated Value' David Winsemius wrote: > > write.csv does exactly what you would expect ... creates a *Comma* > Separated Values file. If you don't want a comma separated value > format then use write.table with sep=";" > > Yo

Re: [R] for loop in nls function

2008-04-29 Thread Yuelin Li
> results[i]<- nls(Tw ~ mu + ((alpha - mu)/(1 + exp(gamma*(B - > Mean_Air, > data = dem16, > start = list(mu = 0.0001, alpha = 21.8, gamma = 0.22, B = 12.8)) > } If you have a variable that codes "site" then you can try something like this to get the parameters over sites.

[R] FOR LOOP w/IFELSE statement help

2008-03-05 Thread zack holden
Dear list, I'm trying to query a string of numbers to identify where in the string the numbers stop increasing (where x[i] == x[i+1]). In example 1 below, I've adapted code from Jim Holt to do this. However, I run into situations where the condition is not met, as in example 2, where the number

[R] for loop looking for file names

2008-12-02 Thread Steven Kennedy
I have a series of csv files in several folders. All begin with a 7 digit number and end with the letter "E" (eg. 0726016E.csv). I want to be able to read a file in to R, take some of the data out of it and store it in a matrix, then move on to the next file and do the same thing. I was planning

Re: [R] for loop if else conditional

2007-10-15 Thread Gabor Grothendieck
See ?seq.Date, e.g. now <- Sys.Date() dd <- seq(now - 20, now, by = "day") dd[as.POSIXlt(dd)$wday %% 6 != 0] and have a look at R News 4/1. On 10/15/07, Vishal Belsare <[EMAIL PROTECTED]> wrote: > date <- as.POSIXlt(Sys.time()) #present date > for (i in 1:difftime(as.PO

[R] For loop for distinguishing negative numbers

2009-07-15 Thread cmga20
Hi i am very new to R and I have been trying to change each individual piece of data in a data set to 10 if it is below 0 and 5 if it is above 0. I know this sounds very easy but i am struggling!! -- View this message in context: http://www.nabble.com/For-loop-for-distinguishing-negative-numbers

Re: [R] for loop for file names

2009-07-30 Thread Jorge Ivan Velez
Dear Chris, Try this: x <- c("a","b","c","d","e","f") sapply(x, function(i){ i <- paste("pred/Pred_pres_",i,"_indpdt", sep ="") load(i) } ) HTH, Jorge On Thu, Jul 30, 2009 at 4:06 PM, waltzmiester wrote: > > I am trying to load binary files in t

Re: [R] for loop for file names

2009-07-30 Thread baptiste auguie
Try this, files = paste('pred/Pred_pres_', letters[1:6], '_indpdt',sep="") lapply(files, load) HTH, baptiste 2009/7/30 waltzmiester : > > I am trying to load binary files in the following fashion > > load("pred/Pred_pres_a_indpdt") > load("pred/Pred_pres_b_indpdt") > load("pred/Pred_pres_c_ind

Re: [R] for loop for file names

2009-07-30 Thread Henrique Dallazuanna
Try this: sapply(sprintf("pred/Pred_pres_%s_indpt", x), load, envir = .GlobalEnv) You need set the envir argument to global environment inside the sapply. On Thu, Jul 30, 2009 at 5:06 PM, waltzmiester wrote: > > I am trying to load binary files in the following fashion > > load("pred/Pred_pres_

Re: [R] for loop for file names

2009-07-30 Thread waltzmiester
Thanks very much for these two solutions, but they are still printing "Pred_pres_[i]_indpdt" on the screen and not executing the function load Chris baptiste auguie-5 wrote: > > Try this, > > files = paste('pred/Pred_pres_', letters[1:6], '_indpdt',sep="") > > lapply(files, load) > > > HT

Re: [R] for loop for file names

2009-07-30 Thread John Kane
I'm just guessing but what about letters <- letters[1:6] mynames <- paste("pred/Pred_pres_",letters,"_indpdt") for(i in 1:6) load(mynames[i]) --- On Thu, 7/30/09, waltzmiester wrote: > From: waltzmiester > Subject: Re: [R] for loop for file names

Re: [R] for loop for file names

2009-07-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of waltzmiester > Sent: Thursday, July 30, 2009 1:29 PM > To: r-help@r-project.org > Subject: Re: [R] for loop for file names > > > Thanks very much f

Re: [R] For Loop Iteration: Variable Counter

2009-08-03 Thread Steve Lianoglou
Hi, On Aug 3, 2009, at 12:09 PM, Vivek Ayer wrote: Hey guys, How do I iterate such that I add 100 to the counter every time? Suppose: for (i in c(1:100)) I want i to be 1, 10, 20, 30, ... instead of 1,2,3,4,5 ... How can this be done? ?seq -steve -- Steve Lianoglou Graduate Student: Com

Re: [R] For Loop Iteration: Variable Counter

2009-08-03 Thread Vivek Ayer
Got it..Thanks Vivek On Mon, Aug 3, 2009 at 9:13 AM, Steve Lianoglou wrote: > Hi, > > On Aug 3, 2009, at 12:09 PM, Vivek Ayer wrote: > >> Hey guys, >> >> How do I iterate such that I add 100 to the counter every time? >> >> Suppose: for (i in c(1:100)) >> >> I want i to be 1, 10, 20, 30, ... inst

Re: [R] FOR LOOP w/IFELSE statement help

2008-03-05 Thread Ted Harding
On 05-Mar-08 23:37:42, zack holden wrote: > Dear list, > I'm trying to query a string of numbers to identify where in the string > the numbers stop increasing (where x[i] == x[i+1]). In example 1 below, > I've adapted code from Jim Holt to do this. However, I run into > situations where the conditi

Re: [R] for loop looking for file names

2008-12-02 Thread jim holtman
To get the file names in the current directory try: list.files(pattern="[[:digit:]]{7}E") On Tue, Dec 2, 2008 at 4:11 PM, Steven Kennedy <[EMAIL PROTECTED]> wrote: > > I have a series of csv files in several folders. All begin with a 7 digit > number and end with the letter "E" (eg. 0726016E.csv)

[R] for loop for extracting linear model info

2009-04-03 Thread Melissa2k9
Hi, I have written a for loop as such: model<-lm(Normalised~Frame,data=All,subset=((Subject==1)&(Filmclip=="Strand"))) summary(model) ### #To extract just the Adjusted R squared ### rsq<-summary(model)[[9]] ##

Re: [R] For loop for distinguishing negative numbers

2009-07-15 Thread tonybreyal
see ?ifelse you didn't specify what happens if a value is exactly zero in the dataset and so i've just bundled it in with the negative case: x <- rnorm(20, 0, 1) y<-ifelse(x<=0, 10, 5) HTH, Tony Breyal cmga20 wrote: > > Hi i am very new to R and I have been trying to change each individual

Re: [R] For loop for distinguishing negative numbers

2009-07-16 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 15.07.2009 17:59:39: > > see ?ifelse > > you didn't specify what happens if a value is exactly zero in the dataset > and so i've just bundled it in with the negative case: > > x <- rnorm(20, 0, 1) > y<-ifelse(x<=0, 10, 5) For this simple case you ca

[R] for-loop for opening a series of files

2008-09-17 Thread Brian Pettegrew
Hello, I am fairly new to R programming. I have a series of netcdf files that I am able to open one at a time using open.ncdf. I want to write this into an R script so that I can successively open each file by date in a for-loop. Any suggestions? Thanks Brian Pettegrew -- Brian Pettegre

[R] for loop or "by" group in EF function

2008-06-03 Thread Ingrid Tohver
Hello, I would like to apply the EF function (a goodness of fit test between predicted (ts2) and observed (Tw) values in the qualV package) to each of the Sites in my data frame. However, when I try the following script, R gives an error message that lists unused arguments, which include th

Re: [R] for loop for extracting linear model info

2009-04-03 Thread Uwe Ligges
Melissa2k9 wrote: Hi, I have written a for loop as such: model<-lm(Normalised~Frame,data=All,subset=((Subject==1)&(Filmclip=="Strand"))) summary(model) ### #To extract just the Adjusted R squared ### rsq<-summary(model)

Re: [R] for loop for extracting linear model info

2009-04-04 Thread Melissa2k9
Uwe Ligges-3 wrote: > > > > Melissa2k9 wrote: >> Hi, >> >> I have written a for loop as such: >> >> model<-lm(Normalised~Frame,data=All,subset=((Subject==1)&(Filmclip=="Strand"))) >> summary(model) >> >> ### >> #To extract just the Adjusted R squared >>

Re: [R] for loop for extracting linear model info

2009-04-04 Thread Uwe Ligges
Melissa2k9 wrote: Uwe Ligges-3 wrote: Melissa2k9 wrote: Hi, I have written a for loop as such: model<-lm(Normalised~Frame,data=All,subset=((Subject==1)&(Filmclip=="Strand"))) summary(model) ### #To extract just the Adjusted R squared

Re: [R] for-loop for opening a series of files

2008-09-17 Thread Yihui Xie
Hi, you may use list.files('dir-of-your-files', ...) to get the paths of all the files, and use file.info() to get the date attribute, then order them by date, and finally in a loop for(i in paths-of-your-files){ open.ncdf(i, ...) ... } Regards, Yihui -- Yihui Xie <[EMAIL PROTECTED]> Phone: +86-(

[R] for loop, my program does not make a cycle

2008-05-14 Thread J S
Dear R community, I wrote a small program using for loop but it does not make cycles. My data: Dataframes: a2, a1, b0 and b1. Vector: d I would like to get b1 for each of i., i.e. totally 11. However, the program gives me b1 only for the last i =11. d<-as.vector(levels(a2$combin2)) for (

[R] For Loop - loading 10 sets of data and calculating

2008-11-07 Thread PDXRugger
I am trying to simplify my code by adding a for loop that will load and compute a sequence of code 10 time. They way i run it now is that the same 8 lines of code are basically reproduced 10 times. I would like to replace the numeric value in the code (e.g. Bin1, Bin2Bin10) each time the loo

Re: [R] for loop, my program does not make a cycle

2008-05-14 Thread jim holtman
You got exactly what you were asking for: the value the last time through the loop. If you are trying to capture all 11 values, then you might consider a list: d<-as.vector(levels(a2$combin2)) a1 <- b1 <- vector('list',11) for (i in 1:11){ a1[[i]] <-a2[a2$combin2%in%d[i],] b1[[i]]<-b0[b0$Date%in%

Re: [R] For Loop - loading 10 sets of data and calculating

2008-11-07 Thread jim holtman
# I would put this in a list in the following manner Bin <- lapply(1:10, function(.file){ #--- #Loads bin data frame from csv files with acres and TAZ data fileName <- paste("I:/Research/Samba/urb_transport_modeling/LUSDR/Workspace/BizLandPrice/data/Bin_lookup_values/Bin", .file,

[R] For loop - how to assign "i" when it is not an element of an index?

2008-10-20 Thread Scotty Nelson
Hello, I'm trying to build a for loop, where I estimate a series of models with different sets of (time series) data. However my for loop doesn't recognize the "i" # code window.1=anomalies.CAK[(positions(anomalies.CAK)>=timeDate("1/1/1971") & positions(anoma

[R] for loop question Documentation and its application for calculating euclidean distance on MDS ordination axis scores

2008-10-01 Thread stephen sefick
?for doesn't return anything help.search("for") doesn't return anything- Is the for loop so prevelant in computer programing that the documentation is implicit or is R paradigm to discourage the use of the for loop. I will post data probably tonight, but here is my problem. I have preformed an MD

  1   2   >