Re: [R] Loop

2013-02-17 Thread Rui Barradas
Hello, As for the first question, you can do something like Timeframemin<-10 Timefram<-1 uFrame <- seq(Timeframemin, Timefram, by = 10) for(u in uFrame) {} As for the second question, the answer is yes, there is a print() function, which can be used for your purpose. Hope this helps

[R] Loop

2013-02-17 Thread Trying To learn again
Hi all, I want to execute a loop of a program: for (u in Timeframemin:Timeframe){} Imagine that Timeframemin<-10 Timefram<-1 Is it posible to execute the loop but only proving from 10 to 1 but jumping 10 each time, for example, execute for 10,20,30.to Timeframe. Other question is,

Re: [R] Loop question?

2013-01-26 Thread Jeff Newmiller
The unlist-sapply-seq_len bit is unnecessarily convoluted, since the infcprodessa function can accept vector inputs. z <- infcprodessa( ab$a, TINF, ab$b, ab$b-TINF ) possibles <- ab[ z >= 15 & z <= 20, ] possibles[ which.min( possibles$a ), ] --

Re: [R] Loop question?

2013-01-26 Thread Berend Hasselman
On 26-01-2013, at 12:31, Andras Farkas wrote: > > Sorry Jeff, probably the new version of Yahoo mail doing the html, I switched > back to the older one hope that takes care of the problem. Let me clarify the > code below: > > TINF <-1 > a <-c(500,750,1000,1250,1500,1750,2000) > b <-c(8,12,18

Re: [R] Loop question?

2013-01-26 Thread Andras Farkas
Andras --- On Sat, 1/26/13, Jeff Newmiller wrote: > From: Jeff Newmiller > Subject: Re: [R] Loop question? > To: "Andras Farkas" , "r-help@r-project.org" > > Date: Saturday, January 26, 2013, 2:09 AM > Please read the Posting Guide > no html email

Re: [R] Loop question?

2013-01-26 Thread David Hugh-Jones
Here's a toy example which you can apply the logic of: dfr <- expand.grid(1:3,1:2) results <- apply(dfr, 1, sum) dfr[results==4,] On 25 January 2013 22:19, Andras Farkas wrote: > > Dear All > > I have the following data (somewhat simplyfied): > > TINF <-1 > a <-c(500,750,1000,1250,1500,1750,

Re: [R] Loop question?

2013-01-25 Thread Jeff Newmiller
Please read the Posting Guide no html email reproducible example please In general, you can use expand.grid to generate all combinations of inputs, compute results as a vector just as long as the expand.grid data frame has rows, and identify which results meet your criteria by a logical test, an

[R] Loop question?

2013-01-25 Thread Andras Farkas
Dear All   I have the following data (somewhat simplyfied):   TINF <-1 a <-c(500,750,1000,1250,1500,1750,2000) b <-c(8,12,18,24,36,48,60,72,96)   following function:   infcprodessa <-function (D, tin, tau, ts)   (D * (1 - exp(-0.048 * tin))/(tin * (0.048*79) * (1 - exp(-0.048 * tau * exp(-0.0

Re: [R] loop correction needed

2013-01-02 Thread arun
tto To: "r-help@r-project.org" Cc: Sent: Wednesday, January 2, 2013 12:00 PM Subject: [R] loop correction needed Dear useRs, i have a data frame with 16 lists in it. each list has variable number of lines. i want to create a loop which will start deleting every 32nd line in each list,

Re: [R] loop correction needed

2013-01-02 Thread David Winsemius
On Jan 2, 2013, at 9:00 AM, eliza botto wrote: Dear useRs, i have a data frame with 16 lists in it. each list has variable number of lines. i want to create a loop which will start deleting every 32nd line in each list, till the end of each list. more precisely if a list has 200 rows i w

[R] loop correction needed

2013-01-02 Thread eliza botto
Dear useRs, i have a data frame with 16 lists in it. each list has variable number of lines. i want to create a loop which will start deleting every 32nd line in each list, till the end of each list. more precisely if a list has 200 rows i want to delete row number 32, 64, 96 and so on...for th

[R] loop for calculating 1-se in rpart

2012-12-07 Thread Andrew Halford
Hi Listers I need to calculate and then plot a frequency histogram of the best tree calculated using the 1-se rule. I have included some code that has worked well for me in the past but it was only for selecting the minimum cross-validation error. I include the code for my model, some relevant out

Re: [R] loop function and integrate?

2012-11-30 Thread faeriewhisper
hello guys! thank u for the help, but u didnt understood what i need. 1st, it is a[i] cuz i want to sum 1 + x[i], for all i's not j. but i've solved it! :) like i said, my code is more complex, but, if you need to integrate several functions in a loop, thats what you should do: w2 = seq(-1,-1/3,l

Re: [R] loop function and integrate?

2012-11-30 Thread Berend Hasselman
On 30-11-2012, at 19:34, Berend Hasselman wrote: > > On 30-11-2012, at 16:08, faeriewhisper wrote: > >> Hi guys! >> I have to compute something and i don't know what i'm doing wrong. my code >> is a bit complex, but imagine that is something like this: >> >> a = c(1,2,3,4) >> ia = length(a)

Re: [R] loop function and integrate?

2012-11-30 Thread Berend Hasselman
On 30-11-2012, at 16:08, faeriewhisper wrote: > Hi guys! > I have to compute something and i don't know what i'm doing wrong. my code > is a bit complex, but imagine that is something like this: > > a = c(1,2,3,4) > ia = length(a) > > x = seq(1,100,length=0.1) > ib = length(x) > > int1 =

Re: [R] loop function and integrate?

2012-11-30 Thread Rui Barradas
Hello, Your code doesn't run without initializing 'ss' to something. And I've made some changes, but I don't understand what you are trying to do. See comments inline. a = c(1,2,3,4) ia = length(a) x = seq(1, 100, by=0.1) # It was 'length = 0.1' (!) ib = length(x) ss <- numeric(ia) # Ne

Re: [R] loop function and integrate?

2012-11-30 Thread faeriewhisper
Now i've managed to do this: funcs <- list() funcs[] # loop through to define functions for(i in 1:ib-1){ # Make function name funcName <- paste( 'func', i, sep = '' ) # make function func = paste('function(x){sin(x + a[', i,'])))}',sep = '') funcs[[funcName]] = eval(parse(

[R] loop function and integrate?

2012-11-30 Thread faeriewhisper
Hi guys! I have to compute something and i don't know what i'm doing wrong. my code is a bit complex, but imagine that is something like this: a = c(1,2,3,4) ia = length(a) x = seq(1,100,length=0.1) ib = length(x) int1 = numeric(ib) b = numeric(ib) for(j in 1:ia) { H = function(x) {

Re: [R] loop command to matrix

2012-11-27 Thread arun
__ From: eliza botto To: "smartpink...@yahoo.com" Sent: Tuesday, November 27, 2012 1:53 PM Subject: RE: [R] loop command to matrix thanks arun. i m more interested in learning commands.  thankyou so much eliza > Date: Tue, 27 Nov 2012 10:45:37 -0800 > From: smartpink...@ya

Re: [R] loop command to matrix

2012-11-27 Thread arun
137.0  -97.28571 A.K. - Original Message - From: eliza botto To: "r-help@r-project.org" Cc: Sent: Tuesday, November 27, 2012 12:51 PM Subject: [R] loop command to matrix Dear UseRs,Extremely sorry for a basic question. I have a matrix of 19 rows and 365 columns. what

Re: [R] loop with date

2012-11-27 Thread Tagmarie
Sorry again, project is part of the rgdal package. Tagmarie -- View this message in context: http://r.789695.n4.nabble.com/loop-with-date-tp4650961p4651005.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing

Re: [R] loop command to matrix

2012-11-27 Thread eliza botto
thanks rui!! how can it be that you advise something and it doesn't work :) eliza > Date: Tue, 27 Nov 2012 18:14:41 + > From: ruipbarra...@sapo.pt > To: eliza_bo...@hotmail.com > CC: r-help@r-project.org > Subject: Re: [R] loop command to matrix > > Hello, >

Re: [R] loop command to matrix

2012-11-27 Thread Rui Barradas
Hello, Try x <- matrix(1:18, ncol = 6) sapply(seq_len(ncol(x)), function(i) x[, i] - rowMeans(x[, -i])) Hope this helps, Rui Barradas Em 27-11-2012 17:51, eliza botto escreveu: Dear UseRs,Extremely sorry for a basic question. I have a matrix of 19 rows and 365 columns. what i want to do is

[R] loop command to matrix

2012-11-27 Thread eliza botto
Dear UseRs,Extremely sorry for a basic question. I have a matrix of 19 rows and 365 columns. what i want to do is the following...First i want to leave out column number 1 and want to calculate the row wise mean of the remaining columns, which will obviously give me 365 values in one column, an

Re: [R] loop with date

2012-11-27 Thread Tagmarie
Ok, sorry, I thought the more complex details might be confusing and nobody might answer. Here is something which looks more like my real dataframe and also what I want to do with it: That's my data frame: myframe <- data.frame (Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00", "24.09.2012 1

Re: [R] loop with date

2012-11-27 Thread arun
   4.00 It is better to show the complex data as an example using dput() A.K. - Original Message - From: Tagmarie To: r-help@r-project.org Cc: Sent: Tuesday, November 27, 2012 9:02 AM Subject: [R] loop with date Hello, I tried to construct my very first loop today and completly

Re: [R] loop with date

2012-11-27 Thread jim holtman
Here is an example of an approach: > myframe <- data.frame (Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00", + "24.09.2012 11:00", +"25.09.2012 09:00", "25.09.2012 10:00", + "25.09.2012 11:00"), + Speed=c(1,1,2,5,1,6)) > myframestime <

Re: [R] loop with date

2012-11-27 Thread R. Michael Weylandt
On Tuesday, November 27, 2012, Tagmarie wrote: > Hello, > I tried to construct my very first loop today and completly failed :-( > Maybe someone can help me? > I have a dataframe somewhat like this one: > > myframe <- data.frame (Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00", > "24.09.2012 11

[R] loop with date

2012-11-27 Thread Tagmarie
Hello, I tried to construct my very first loop today and completly failed :-( Maybe someone can help me? I have a dataframe somewhat like this one: myframe <- data.frame (Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00", "24.09.2012 11:00", "25.09.2012 09:0

Re: [R] loop to subtract arrays / error

2012-11-19 Thread arun
(res3,3) #  V1 V2 #1 -0.001 -0.001 #2  0.003  0.003 #3 -1.181  0.169 A.K. - Original Message - From: iembry To: r-help@r-project.org Cc: Sent: Sunday, November 18, 2012 8:41 PM Subject: [R] loop to subtract arrays / error Hi everyone, I am having trouble with creating a

Re: [R] loop to subtract arrays / error

2012-11-19 Thread Irucka Embry
Hi Arun, thanks for your assistance. That worked as well. Irucka <-Original Message-> >From: arun [smartpink...@yahoo.com] >Sent: 11/19/2012 7:22:09 AM >To: iruc...@mail2world.com >Cc: r-help@r-project.org >Subject: Re: [R] loop to subtract arrays / error >

Re: [R] loop to subtract arrays / error

2012-11-19 Thread Irucka Embry
Hi Rui, thank-you. That was simple and worked great. Irucka <-Original Message-> >From: Rui Barradas [ruipbarra...@sapo.pt] >Sent: 11/19/2012 4:13:24 AM >To: iruc...@mail2world.com >Cc: r-help@r-project.org >Subject: Re: [R] loop to subtract arrays / error &g

Re: [R] loop to subtract arrays / error

2012-11-19 Thread Irucka Embry
Hi Rui Barradas, how are you? Thank-you very much. That worked perfectly. Irucka Embry <-Original Message-> >From: Rui Barradas [ruipbarra...@sapo.pt] >Sent: 11/19/2012 4:05:11 AM >To: iruc...@mail2world.com >Cc: r-help@r-project.org >Subject: Re: [R] loop to su

Re: [R] loop to subtract arrays / error

2012-11-19 Thread Rui Barradas
Hello, Or simpler, since Vobsr only has one column: Xjj <- as.vector(Vobsr) - Vsimr Hope this helps, Rui Barradas Em 19-11-2012 10:05, Rui Barradas escreveu: Hello, Try the following. Xjj <- matrix(nrow = 101, ncol = 1000) for (i in 1:dim(Vsimr)[2]) { Xjj[, i] <- Vobsr - Vsimr[, i] } H

Re: [R] loop to subtract arrays / error

2012-11-19 Thread Rui Barradas
Hello, Try the following. Xjj <- matrix(nrow = 101, ncol = 1000) for (i in 1:dim(Vsimr)[2]) { Xjj[, i] <- Vobsr - Vsimr[, i] } Hope this helps, Rui Barradas Em 19-11-2012 01:41, iembry escreveu: Hi everyone, I am having trouble with creating a loop to subtract arrays. In R, this is what

[R] loop to subtract arrays / error

2012-11-18 Thread iembry
Hi everyone, I am having trouble with creating a loop to subtract arrays. In R, this is what I have done: > Vobsr <- read.csv("Observed_Flow.csv", header = TRUE, sep =",") # see data > below > Vsimr <- read.csv("1000Samples_Vsim.csv", header = TRUE, sep =",") # see > data below > Vobsr <- as.matr

Re: [R] Loop over several Variables, add on question

2012-11-02 Thread bchr
Hey John, thanks for making me notice that document - I just skipped over it the past hour and I think I like that very condensed If you want to do this ->it works like that approach. Besides that I had the impression, though that it's content - while more strongly condensed - is basically not too

Re: [R] Loop over several Variables, add on question

2012-11-02 Thread John Kane
In Line John Kane Kingston ON Canada > -Original Message- > From: bochrist...@web.de > Sent: Fri, 2 Nov 2012 05:34:48 -0700 (PDT) > To: r-help@r-project.org > Subject: Re: [R] Loop over several Variables, add on question > > Hey Petr, > > thanks for answer

Re: [R] Loop over several Variables, add on question

2012-11-02 Thread bchr
Thanks very much Petr, that one did just fine! I just wanted to say that it's not that I did no reading at all (in fact I use a book called R for Stata users by Muenchen/Hilbe and another German book called Programming in R when you translate the title) - so yes I am aware that R works quite diff

Re: [R] Loop over several Variables, add on question

2012-11-02 Thread PIKAL Petr
g > Subject: Re: [R] Loop over several Variables, add on question > > Hey Petr, > > thanks for answering. First to your question: I use rename from the > reshape package. > You are probably right to assume that I do not have a to extensive > reading background in R -

Re: [R] Loop over several Variables, add on question

2012-11-02 Thread Bert Gunter
Inline. On Fri, Nov 2, 2012 at 5:34 AM, bchr wrote: > Hey Petr, > > thanks for answering. First to your question: I use rename from the reshape > package. > You are probably right to assume that I do not have a to extensive reading > background in R - basically I had to dive right in (which prob

Re: [R] Loop over several Variables, add on question

2012-11-02 Thread bchr
Hey Petr, thanks for answering. First to your question: I use rename from the reshape package. You are probably right to assume that I do not have a to extensive reading background in R - basically I had to dive right in (which probably isn't a good idea, but I could not change that). Having a s

Re: [R] Loop over several Variables, add on question

2012-11-02 Thread PIKAL Petr
Hi > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of bchr > Sent: Friday, November 02, 2012 11:57 AM > To: r-help@r-project.org > Subject: [R] Loop over several Variables, add on question > > Hey ev

[R] Loop over several Variables, add on question

2012-11-02 Thread bchr
Hey everyone, I have again a loop question: After generating the dataset using Jan’s approach from my previous posting (http://r.789695.n4.nabble.com/Loop-over-several-variables-td4648112.html) I want to rename the Variables in the new dataset so that all y will be called tiy. Doing it separately

Re: [R] Loop over several variables

2012-11-01 Thread bchr
Oh hey Jan, sorry, I just saw I did not read correctly and mistook your quote of Don's mail as a signature. So thank's to you for the second posting Bernhard -- View this message in context: http://r.789695.n4.nabble.com/Loop-over-several-variables-tp4648112p4648132.html Sent from the R help

Re: [R] Loop over several variables

2012-11-01 Thread bchr
Hey Don, I just saw your second post ... that's even better! Thanks again Bernhard -- View this message in context: http://r.789695.n4.nabble.com/Loop-over-several-variables-tp4648112p4648131.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] Loop over several variables

2012-11-01 Thread bchr
Hey Don, many thanks, I tried that and it works just fine. I have two questions though: 1. In Addition to generating the t1-t5 (I have five iterations, in fact), the code will generate an additional ti(without subscript), which seems to be a copy of ti5. Is that what it should do ( and if yes, wh

Re: [R] Loop over several variables

2012-11-01 Thread Jan van der Laan
Or ti <- aggregate(dataframename[paste0("y", 1:3)], by=dataframename["aggregationvar"], sum,na.rm=TRUE) which gives you all results in one data.frame. Jan "MacQueen, Don" schreef: Many ways. Here is one: ### supposing you have y1, y2, and y3 in your data frame for (i in

Re: [R] Loop over several variables

2012-11-01 Thread MacQueen, Don
Many ways. Here is one: ### supposing you have y1, y2, and y3 in your data frame for (i in 1:3) { yi <- paste('y',i,sep='') ti <- aggregate(dataframename[[yi]], by=data.frame(dataframename$aggregationvar), sum,na.rm=TRUE) assign( paste('ti',i,sep='') , ti, '.GlobalE

[R] Loop over several variables

2012-11-01 Thread bchr
Hey everybody, I am looking for a way to loop commands over several variables in a dataframe. Basically I want to do something like this: ti1<-aggregate(dataframename$y1, by=data.frame(dataframename$aggregationvar), sum,na.rm=TRUE) This works fine as it is but i wan

Re: [R] loop of quartile groups

2012-10-17 Thread David Winsemius
On Oct 17, 2012, at 7:23 AM, Charles Determan Jr wrote: Greetings R users, My goal is to generate quartile groups of each variable in my data set. I would like each experiment to have its designated group added as a subsequent column. I can accomplish this individually with the followin

Re: [R] loop of quartile groups

2012-10-17 Thread Rui Barradas
Hello, There's no function cut2() but it's not very difficult to write one. I've named your data example 'dat', it saves keystrokes. Try the following. dat <- structure(...etc...) cut2 <- function(x, g = 0){ cut(x, breaks = c(-Inf, seq(min(x), max(x), length.out = g))) } fun <- function(

[R] loop of quartile groups

2012-10-17 Thread Charles Determan Jr
Greetings R users, My goal is to generate quartile groups of each variable in my data set. I would like each experiment to have its designated group added as a subsequent column. I can accomplish this individually with the following code: brks <- with(data_variables, cut2(var2, g=

Re: [R] loop for column substraction of a matrix

2012-10-05 Thread Rui Barradas
,1,sum)) #or res1<-mapply(FUN=function(i) mat1[,i]-rowSums(mat1), 1:ncol(mat1)) A.K - Original Message - From: eliza botto To: "r-help@r-project.org" Cc: Sent: Friday, October 5, 2012 4:05 PM Subject: [R] loop for column substraction of a matrix Dear useRs, I have a

Re: [R] loop for column substraction of a matrix

2012-10-05 Thread eliza botto
Dear Arun and Barradas, millions of thanks. you guys always rock. regards eliza > Date: Fri, 5 Oct 2012 14:41:38 -0700 > From: smartpink...@yahoo.com > Subject: Re: [R] loop for column substraction of a matrix > To: eliza_bo...@hotmail.com > CC: ruipbarra...@sapo.pt; r-help@r-proj

Re: [R] loop for column substraction of a matrix

2012-10-05 Thread arun
1[,i]-apply(mat1,1,sum #or res1<-sapply(1:ncol(mat1), function(i) mat1[,i]-apply(mat1,1,sum)) #or res1<-mapply(FUN=function(i) mat1[,i]-rowSums(mat1), 1:ncol(mat1)) A.K  - Original Message - From: eliza botto To: "r-help@r-project.org" Cc: Sent: Friday, October 5, 201

Re: [R] loop for column substraction of a matrix

2012-10-05 Thread arun
: Friday, October 5, 2012 4:05 PM Subject: [R] loop for column substraction of a matrix Dear useRs, I have a matrix with 38 columns and 365 rows. what i want to do is the following. 1. subtracting from each column, first itself and then all the remaining columns. More precisely, from colu

Re: [R] loop for column substraction of a matrix

2012-10-05 Thread Rui Barradas
Hello, 1. Let me refrase it a bit. For each column, sum all others and take the symmetric. mat <- matrix(1:30, ncol = 3) sapply(seq_len(ncol(mat)), function(i) -rowSums(mat[, -i])) 2. write.table (maybe using sep = "\t" ?) and send the file to printer. Hope this helps, Rui Barradas Em 05

[R] loop for column substraction of a matrix

2012-10-05 Thread eliza botto
Dear useRs, I have a matrix with 38 columns and 365 rows. what i want to do is the following. 1. subtracting from each column, first itself and then all the remaining columns. More precisely, from column number 1, i will first subtract itself(column 1) and then the remaining 37 columns.

[R] Loop from List in Geospatial Modeling Environment

2012-08-23 Thread crudeen
Does anyone know how to loop in GME using a list of text values. I am trying to create home ranges for each animal in a point shapefile of locations. Here is an example of the Command Text I am trying to use: l<-'SGF4037', 'SGF4244'; for (i in ls()){ kde(in=paste("SGF.shp"), out=paste(i,"_SGF.i

Re: [R] Loop for readLines(URL[i]) fails when URL returns Error 404

2012-08-22 Thread Noia Raindrops
Hello, For example: url <- c("http://www.example.com";, "http://www.example5.com";) res <- vector("list", length(url)) for (i in 1:length(url)) res[[i]] <- try(readLines(url[i]), silent = TRUE) res[[2]] ## [1] "Error in file(con, \"r\") : cannot open the connection\n" ## attr(,"class") ## [1] "tr

[R] Loop for readLines(URL[i]) fails when URL returns Error 404

2012-08-22 Thread Shelby McIntyre
I have a loop over readLines(URL[i]) which works fine until it hits a bad URL (e.g., a URL that returns a 404 Error). How can I handle this with a test for this error condition. I read the tryCatch( … ) description but can't figure out how to apply it here. Perhaps there is something else that

Re: [R] loop for, error: obj type 'closure' not subsetable

2012-07-26 Thread Rui Barradas
Hello, Simple, look carefully at what you have, rho is a function (type closure), the vector is rhoes. And you are trying to print rho[i], the i-th function in the "vector" called rho. print( rhoes[i] ) # works Hope this helps, Rui Barradas Em 26-07-2012 06:40, Rafael_Leon escreveu: Hi e

[R] loop for, error: obj type 'closure' not subsetable

2012-07-25 Thread Rafael_Leon
Hi everyone, I've got the following problem: I've got a matrix [1000,2] and two vectors. In very matrix row there is two coefficients b0 and b1. The vectors are two variables x and y. I want to do a loop to take b0 and b1 and with x and y calculate the residual of a linear model and calculate t

Re: [R] loop searching the id corresponding to the given index (timestamp)

2012-07-18 Thread Yolande Tra
Thank you Rui. Very helpful. Yolande. On Wed, Jul 18, 2012 at 1:37 PM, Rui Barradas wrote: > Hello, > > Try the following. > > > for(i in 1:dim(diveData_2008)[1]){ > # Which dive is this observation from > thisIndex <- as.character(index(diveData_**2008[i,])) > thisIndex <- as.PO

Re: [R] loop searching the id corresponding to the given index (timestamp)

2012-07-18 Thread Rui Barradas
Hello, Try the following. for(i in 1:dim(diveData_2008)[1]){ # Which dive is this observation from thisIndex <- as.character(index(diveData_2008[i,])) thisIndex <- as.POSIXct(thisIndex) dive_id <- diveCond_all$dive_id[diveCond_all$timestamp == thisIndex] #

Re: [R] loop searching the id corresponding to the given index (timestamp)

2012-07-18 Thread Yolande Tra
it is a function from library(xts) On Wed, Jul 18, 2012 at 1:15 PM, Jean V Adams wrote: > What is the function index() that you use in this line of code? > thisIndex <- as.character(index(diveData_2008[i,])) > > Is it from some package? Or a function you wrote yourself? > I'm trying to run the

Re: [R] loop searching the id corresponding to the given index (timestamp)

2012-07-18 Thread Jean V Adams
What is the function index() that you use in this line of code? thisIndex <- as.character(index(diveData_2008[i,])) Is it from some package? Or a function you wrote yourself? I'm trying to run the code you submitted, but I don't have a function called index(). Jean Yolande Tra wrote on 07/18

[R] loop searching the id corresponding to the given index (timestamp)

2012-07-18 Thread Yolande Tra
Hello, I have the following loop for two data sets: diveData_2008 and diveData_2009. It uses two other data: diveCond_all and fishTable. The problem is at the point to identify the dive_id for the given index (index is timestamp). It keeps on saying for the1st loop Error in fishReport$dive_id[i] <

Re: [R] loop for regression

2012-07-04 Thread Joshua Wiley
>>> (Intercept) Market >>> -31 >>> >>> >>> $Stock2 >>> >>> Call: >>> lm(formula = x ~ Market, data = dat1) >>> >>> Coefficients: >>> (Intercept) Market >>>

Re: [R] loop for regression

2012-07-04 Thread arun
  Market    1   1   1    A.K. From: Bert Gunter To: arun Cc: Akhil dua ; R help Sent: Wednesday, July 4, 2012 2:48 PM Subject: Re: [R] loop for regression Please carefully read ?lm. As I previously told the OP, no looping/apply is necessary. The

Re: [R] loop for regression

2012-07-04 Thread Joshua Wiley
gt;> >> Coefficients: >> (Intercept) Market >> -21 >> >> >> $Stock3 >> >> Call: >> lm(formula = x ~ Market, data = dat1) >> >> Coefficients: >> (Intercept) Market >> -11 >

Re: [R] loop for regression

2012-07-04 Thread Bert Gunter
gt; > Coefficients: > (Intercept) Market > -11 > > A.K. > > > > > - Original Message - > From: Akhil dua > To: r-help@r-project.org > Cc: > Sent: Wednesday, July 4, 2012 1:08 AM > Subject: [R] loop for regression >

Re: [R] loop for regression

2012-07-04 Thread arun
ct.org Cc: Sent: Wednesday, July 4, 2012 1:08 AM Subject: [R] loop for regression -- Forwarded message -- From: Akhil dua Date: Wed, Jul 4, 2012 at 10:33 AM Subject: To: r-help@r-project.org Hi everyone I have data on stock prices and market indices and I need to run a sepera

Re: [R] loop for regression

2012-07-03 Thread Joshua Wiley
Hi, A few comments. First a for loop is probably not optimally efficient. Consider instead (using a bulit in example dataset): lm(cbind(mpg, hp) ~ cyl + vs, data = mtcars) which gives: Call: lm(formula = cbind(mpg, hp) ~ cyl + vs, data = mtcars) Coefficients: mpg hp (Inter

Re: [R] loop for regression

2012-07-03 Thread Bert Gunter
?lm and note in particular the section beginning "If response is a matrix..." -- Bert On Tue, Jul 3, 2012 at 10:08 PM, Akhil dua wrote: > -- Forwarded message -- > From: Akhil dua > Date: Wed, Jul 4, 2012 at 10:33 AM > Subject: > To: r-help@r-project.org > > > Hi everyone I > h

Re: [R] loop for regression

2012-07-03 Thread Bert Gunter
Homework? (We don't do homework here). -- Bert On Tue, Jul 3, 2012 at 10:08 PM, Akhil dua wrote: > -- Forwarded message -- > From: Akhil dua > Date: Wed, Jul 4, 2012 at 10:33 AM > Subject: > To: r-help@r-project.org > > > Hi everyone I > have data on stock prices and market ind

[R] loop for regression

2012-07-03 Thread Akhil dua
-- Forwarded message -- From: Akhil dua Date: Wed, Jul 4, 2012 at 10:33 AM Subject: To: r-help@r-project.org Hi everyone I have data on stock prices and market indices and I need to run a seperate regression of every stock on market so I want to write a "for loop" so that I wo

Re: [R] loop in list

2012-07-01 Thread Rui Barradas
Hello, Sorry, forgot to Cc the list. Em 01-07-2012 01:24, R. Michael Weylandt escreveu: I might think replicate() is slightly more idiomatic, but I'm not in a position to check if simplify=FALSE will keep a list. It does: class(replicate(20, f(1))) # "matrix" class(replicate(20, f(1), s

Re: [R] loop in list

2012-06-30 Thread R. Michael Weylandt
I might think replicate() is slightly more idiomatic, but I'm not in a position to check if simplify=FALSE will keep a list. Best, Michael On Jun 30, 2012, at 7:13 PM, Rui Barradas wrote: > Hello, > > You can avoid the loop using lapply. > > f <- function(x) sample(100, 10) > samp.list <- l

Re: [R] loop in list

2012-06-30 Thread Rui Barradas
Hello, You can avoid the loop using lapply. f <- function(x) sample(100, 10) samp.list <- lapply(1:20, f) will choose 20 samples of 10 integers up to 100 and put them in a list. All you need is to write a function f(). f() must have an argument, even if it doesn't use it. If you need other ar

Re: [R] loop in list

2012-06-30 Thread arun
23.65078 --- A.K. - Original Message - From: solafah bh To: R help mailing list Cc: Sent: Saturday, June 30, 2012 3:34 PM Subject: [R] loop in list Hello I have a loop to sample 20 samples and I want to put them in one list, how I can make this??   Regards Sulafah     [[alternative HTM

Re: [R] loop in list

2012-06-30 Thread Greg Snow
Instead of a loop you can use the replicate or lapply functions which will create lists for you. otherwise you can start with an empty list (mylist <- list() ) then add to the list in each iteration of the loop: for(i in 1:10) { mylist[[i]] <- myfunction(i) } On Sat, Jun 30, 2012 at 1:34

[R] loop in list

2012-06-30 Thread solafah bh
Hello I have a loop to sample 20 samples and I want to put them in one list, how I can make this??   Regards Sulafah [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE d

Re: [R] loop through and modify multiple data frames

2012-06-29 Thread arun
Hi Jan, Glad it helped you in some way.  I am also copying to rhelp as your solution might be useful for future reference. A.K. - Original Message - From: Jan Näs To: arun Cc: Sent: Friday, June 29, 2012 5:02 AM Subject: Re: [R] loop through and modify multiple data frames Thank

Re: [R] loop through and modify multiple data frames

2012-06-28 Thread arun
0.5   7.5 2 Trud 0.4   6.0 3 Sind 0.6   9.0 4  Rav 0.8  12.0 There might be an easy way in loop to get the same result. A.K. - Original Message - From: Jan Näs To: r-help@r-project.org Cc: Sent: Thursday, June 28, 2012 5:10 AM Subject: [R] loop through a

Re: [R] loop through and modify multiple data frames

2012-06-28 Thread Tal Galili
Hi Jan, You can do it in two ways. The simplest one is the following. The first option is to use $. Here is how: dogs <- data.frame(a = 1:10, b = 10:1) dogs$c <- dogs$a+dogs$b dogs The second way it to use ?within Contact Details:--

[R] loop through and modify multiple data frames

2012-06-28 Thread Jan Näs
Hi Newbie question: I have a set of data frames that I want to do the same calculations on each. I've found out that I can put them in a list and loop through the list to do the calculation, but not put the results back into each data.frame.. For example three data frames cats, dogs, birds wher

Re: [R] Loop for multiple plots in figure

2012-06-27 Thread baptiste auguie
You can use main = unique(d$Subject) to solve this problem. HTH, b. On 27 June 2012 08:49, Marcel Curlin wrote: > Well at this point I have what I need (rough plot for data exploration) but > the simplicity of the first approach is quite elegant and it has become a > learning project. I have su

Re: [R] Loop for multiple plots in figure

2012-06-27 Thread Marcel Curlin
Well at this point I have what I need (rough plot for data exploration) but the simplicity of the first approach is quite elegant and it has become a learning project. I have succeeded in formatting the overall plot OK but have not been able to solve the problem of titles or any kind of label/legen

Re: [R] Loop for multiple plots in figure

2012-06-26 Thread baptiste auguie
Try this alternative solution using only base functions: # split the data into 4 data.frames l <- split(data, data$Subject) names(l) # set up the graph parameters par(mfrow=n2mfrow(length(l)), mar=c(4,4,1,1), mgp = c(2, 1, 0)) # good old for loop over the subject names for( n in names(l)){ d <-

Re: [R] Loop for multiple plots in figure

2012-06-26 Thread Marcel Curlin
This solution works really nicely & I learned much by working through it. However but I am having trouble with subplot formatting; setting main=d$Subject results in the correct title over each plot but repeated multiple times. Also I can't seem to format the axis labels and numbers to reduce the sp

Re: [R] Loop for multiple plots in figure

2012-06-25 Thread baptiste auguie
Hi, Here's one approach: plot_one <- function(d){ with(d, plot(Xvar, Yvar, t="n")) # set limits with(d[d$param1 == 0,], lines(Xvar, Yvar, lty=1)) # first line with(d[d$param1 == 1,], lines(Xvar, Yvar, lty=2)) # second line } par(mfrow=c(2,2)) plyr::d_ply(data, "Subject", plot_one) HTH,

[R] Loop for multiple plots in figure

2012-06-24 Thread Marcel Curlin
Hello, I have longitudinal data of the form below from N subjects; I am trying to create figure with N small subplots on a single page, in which each plot is from only one subject, and in each plot there is a separate curve for each value of param1. So in this case, there would be four plots on t

Re: [R] Loop Help

2012-06-18 Thread @ngel
Thank you Jeff, that sounds like the solution to my problem but how would I do that code-wise? could you please help? -- View this message in context: http://r.789695.n4.nabble.com/Loop-Help-tp4633558p4633701.html Sent from the R help mailing list archive at Nabble.com. _

Re: [R] Loop Help

2012-06-18 Thread Özgür Asar
@angel, You can try append option in write.table for e.g. for(i in 1:20) write.table(i,"out.txt",append=T,sep="\t",row.names=F,col.names=F) This will help you save your all results by writing each results on subsequent rows. Hope this helps Ozgur >Hello Jim >thank you so much for your respons

Re: [R] Loop Help

2012-06-18 Thread David Winsemius
On Jun 18, 2012, at 5:47 AM, @ngel wrote: I think that for now I'll keep it There is no "it" in this message. Users of Nabble often fail to read the POsitng Guide where it is requested that you include context. as is and try to clean the data in excel. Could someone please tell me how c

Re: [R] Loop Help

2012-06-18 Thread Jeff Newmiller
Then don't do that. write.csv is designed to write a complete matrix or data frame in one call. Combine your list of matrices into one (e.g. using sapply) and write that in one call afterward rather than piecewise as you do the calculations. -

Re: [R] Loop Help

2012-06-18 Thread @ngel
Hello Jim thank you so much for your response. When I use write.csv, on the csv file is saved only the last loop So when I write results.matrix <- apply(degree_w(net.static[[i]]), 2, mean) write.csv(results.matrix, file = "results.csv") instead of getting a 550 line document with all loop result

Re: [R] Loop Help

2012-06-18 Thread jim holtman
What do you mean by "only the last j"? write.csv writes to a file you specify and I assume that you are changing the file name if you are making successive writes. You need to provide more detail. On Mon, Jun 18, 2012 at 5:47 AM, @ngel wrote: > I think that for now I'll keep it as is and try to

<    1   2   3   4   5   6   7   >