Re: [R-es] loop con matriz que cambia de nombre

2018-06-24 Thread Manuel Mendoza
>> > } >> > >> > Con eso generarias 7 matrices de 5x3, llamadas matriz1, matriz2,... >> > >> > Obtener Outlook para Android<https://aka.ms/ghei36> >> > >> > >> > From: R-help-es on behalf of >&g

Re: [R-es] loop con matriz que cambia de nombre

2018-06-23 Thread Javier Marcuzzi
l=5,nrow=3)) > >> > > >> > } > >> > > >> > Con eso generarias 7 matrices de 5x3, llamadas matriz1, matriz2,... > >> > > >> > Obtener Outlook para Android<https://aka.ms/ghei36> > >> > > >> >

Re: [R-es] loop con matriz que cambia de nombre

2018-06-23 Thread Manuel Mendoza
___ > From: R-help-es on behalf of > Manuel Mendoza > Sent: Friday, June 22, 2018 10:15:55 AM > To: r-help-es@r-project.org > Subject: [R-es] loop con matriz que cambia de nombre > > > Buenos días. Quiero hacer un for (j), anidado en otro for (i). En

Re: [R-es] loop con matriz que cambia de nombre

2018-06-22 Thread Carlos J. Gil Bellosta
gt; > > Con eso generarias 7 matrices de 5x3, llamadas matriz1, matriz2,... > > > > Obtener Outlook para Android<https://aka.ms/ghei36> > > > > ________ > > From: R-help-es on behalf of > > Manuel Mendoza > > Sent: Friday,

Re: [R-es] loop con matriz que cambia de nombre

2018-06-22 Thread Manuel Mendoza
___ From: R-help-es on behalf of Manuel Mendoza Sent: Friday, June 22, 2018 10:15:55 AM To: r-help-es@r-project.org Subject: [R-es] loop con matriz que cambia de nombre Buenos días. Quiero hacer un for (j), anidado en otro for (i). En el 2º for, en cada iteración ha de crear una m

Re: [R-es] loop con matriz que cambia de nombre

2018-06-22 Thread Manuel Mendoza
i36> From: R-help-es on behalf of Manuel Mendoza Sent: Friday, June 22, 2018 10:15:55 AM To: r-help-es@r-project.org Subject: [R-es] loop con matriz que cambia de nombre Buenos días. Quiero hacer un for (j), anidado en otro for (i). En el 2º for, en cada ite

[R-es] loop con matriz que cambia de nombre

2018-06-22 Thread Manuel Mendoza
Buenos días. Quiero hacer un for (j), anidado en otro for (i). En el 2º for, en cada iteración ha de crear una matriz vacía: mat <- matrix(nrow=nrow(data),ncol=19) pero llamándola de forma distinta cada vez. El nombre ha de ser: paste("D",i,colnames(Data[j]),sep=""). Llevo un rato

Re: [R] nested loop

2017-09-09 Thread Ek Esawi
I would try fininterval as well. It should do what you have asked provided that you take care of the issue Ulrik pointed out. Best of luck--EK On Fri, Sep 8, 2017 at 6:15 AM, Hemant Sain wrote: > i have a vector containing values ranging from 0 to 24 > i want to create

[R] nested loop

2017-09-08 Thread Hemant Sain
i have a vector containing values ranging from 0 to 24 i want to create another variable which can categorize those values like this please help me with an R code Thanks *Value New_Var*10 -5 30 -5 50 -5 96-10 76-10 5

Re: [R] Nested loop R code

2017-09-08 Thread Ulrik Stervbo
Hi Hemant, please write to the r-help list in the future. Look at the cut () function to solve your problem. Also, you have a problem in your example - 5 is placed in two different categories. HTH Ulrik On Fri, 8 Sep 2017 at 12:16 Hemant Sain wrote: > i have a vector

Re: [R] R loop function in Tableau

2017-07-07 Thread David Winsemius
> On Jul 6, 2017, at 2:19 PM, Dai, Shengyu <da...@rpi.edu> wrote: > > Hi R helpers, > > > > I hope this email finds you well. > > > > I am having trouble with R loop function in Tableau. > There is no "R loop function". (There is an R `

[R] R loop function in Tableau

2017-07-07 Thread Dai, Shengyu
Hi R helpers, I hope this email finds you well. I am having trouble with R loop function in Tableau. Please see the attachment of a simple dataset. The problem is to test whether the value of columns is match. Because Tableau do not have iteration function, I coded “if statement

Re: [R] For loop

2017-06-22 Thread Nordlund, Dan (DSHS/RDA)
ment of Social and Health Services > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ahmed > Attia > Sent: Thursday, June 22, 2017 9:50 AM > To: r-help > Subject: [R] For loop > > Hello R users, > > The code below is for loop i

Re: [R] For loop

2017-06-22 Thread Rui Barradas
Hello, Without correcting your code, it's obvious that the expressions like leafbiom97$Date == "i" and all others with"i" and "i - 1" are wrong. leafbiom97$Date is of class Date, not character. And, besides, for(i in ...) makes of i a numeric variable that has nothing to do with "i". This "i"

[R] For loop

2017-06-22 Thread Ahmed Attia
Hello R users, The code below is for loop in R that I want to do to following calculation at each time i and i-1 in 2:75 dataset (Litterfall_Ahmed97). ac = ((LeafBiog at date i -LeafBiog at date i-1, dataset = leafbiom97) + (littperiod at date i, dataset= Litterfall_Ahmed97))/(sum (GPP from

Re: [R] for loop in R

2017-01-12 Thread jennifer . sheng2002
That is right, Bob. Only one loop for now, since I do not know how to set up the 2nd loop. Any advice from the community? Thank you! Sent from my iPhone > On Jan 12, 2017, at 4:49 PM, Robert Sherry wrote: > > I only see one for loop in your code. I am wondering if you

Re: [R] for loop in R

2017-01-12 Thread Robert Sherry
I only see one for loop in your code. I am wondering if you want a second for loop based upon the length of newdata. I would also think that you do not need the second call to set.seed. Bob On 1/12/2017 4:44 PM, Jennifer Sheng wrote: Dear friends, I am working on a double loop using for.

[R] for loop in R

2017-01-12 Thread Jennifer Sheng
Dear friends, I am working on a double loop using for. One level of loop is to predict N times for each subject, and the second level is to predict M times for the every subject, one subject after one subject. Please note every subject have different N or M rows of data. Any advice? Thank

Re: [R] for loop is looping only once

2016-11-17 Thread Duncan Murdoch
On 17/11/2016 6:26 AM, Ulrik Stervbo wrote: Hi Georg, Your for loop iterates over just one value, to get it to work as you intend use for(item in 1:length(kpis)){} That usually works, but fails often enough that we recommend using for (item in seq_along(kpis)) {} (The failures happen if

Re: [R] for loop is looping only once

2016-11-17 Thread Ulrik Stervbo
Hi Georg, Your for loop iterates over just one value, to get it to work as you intend use for(item in 1:length(kpis)){} HTH Ulrik On Thu, 17 Nov 2016 at 12:18 wrote: > Hi All, > > I need to execute a loop on variables to compute several KPIs. > Unfortunately the for

[R] for loop is looping only once

2016-11-17 Thread G . Maubach
Hi All, I need to execute a loop on variables to compute several KPIs. Unfortunately the for loop is executed only once for the last KPI given. The code below illustrates my current solution but is not completely necessary to spot the problem. I just give an idea what I am doing overall.

Re: [R] Simple loop problem

2016-10-31 Thread William Dunlap via R-help
Did you mean 'tolower' instead of 'to lower' in your example? Or is there a similarly named function that converts the levels of a factor to lower case instead of converting the factor to a character vector and then lower-casing that? > d %>% dplyr::mutate_if(is.factor, tolower) NumF1 F2 1

Re: [R] Simple loop problem

2016-10-31 Thread William Dunlap via R-help
Use tolower on the levels of the factor columns. E.g., > d <- data.frame(Num=1:3, F1=c("One","Two","Three"), F2=c("A","B","a")) > str(d) 'data.frame': 3 obs. of 3 variables: $ Num: int 1 2 3 $ F1 : Factor w/ 3 levels "One","Three",..: 1 3 2 $ F2 : Factor w/ 3 levels "a","A","B": 2 3 1 >

Re: [R] Simple loop problem

2016-10-31 Thread David L Carlson
r-help@r-project.org Subject: [R] Simple loop problem Hi everybody, I’m new to R and i’m trying to learn fundamentals. I’m facing a small problem for which i can’t find a solution online. What i want to do: write a function to lower case for all the columns in my data.frame if they respec

[R] Simple loop problem

2016-10-31 Thread Yahya Laraki
Hi everybody, I’m new to R and i’m trying to learn fundamentals. I’m facing a small problem for which i can’t find a solution online. What i want to do: write a function to lower case for all the columns in my data.frame if they respect a condition (class = factor) This code works, but for

Re: [R] better loop for simulation

2016-06-18 Thread Dalthorp, Daniel
try: n.questions <- 10 # or however many you want mult.choice <- 2 scores <- rbinom(1000, size = n.questions, prob = 1/mult.choice) On Sat, Jun 18, 2016 at 3:12 PM, Naresh Gurbuxani < naresh_gurbux...@hotmail.com> wrote: > I want to calculate a function many times over. My solution below

Re: [R] better loop for simulation

2016-06-18 Thread Duncan Murdoch
On 18/06/2016 6:12 PM, Naresh Gurbuxani wrote: I want to calculate a function many times over. My solution below works, but does not seem very elegant. # my function to run many times over stud.score <- function(n.questions, mult.choice = 2) { prob.success <- 1 / mult.choice

Re: [R] better loop for simulation

2016-06-18 Thread jim holtman
use replicate: > stud.score <- function(n.questions, mult.choice = 2) { + prob.success <- 1 / mult.choice + answers <- (runif(n.questions) < prob.success) + return(sum(answers)) + } > > # create 1000 results > result <- replicate(1000, stud.score(10)) > > # look at

Re: [R] R [loop statement ]

2016-04-16 Thread Jim Lemon
Hi tan sj, It is by no means easy to figure out what you want without the code, but If I read your message correctly, you can run the loops either way. When you have nested loops producing output, it is often a good idea to include the parameters for each run in the output as well as the result so

[R] R [loop statement ]

2016-04-15 Thread tan sj
hi, i am new in this field. I am now writing a code in robustness simulation study. I have written a brief code "for loop" for the factor (samples sizes d,std deviation ) , i wish to test them in gamma distribution with equal and unequal skewness, with the above for loop in a single code if

Re: [R] MACRO-LOOP in R

2016-02-19 Thread Thierry Onkelinx
Please keep the mailinglist in cc. You should be able to solve this after reading the helpfiles of ?dplyr::mutate and ?tidyr::spread Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team

Re: [R] MACRO-LOOP in R

2016-02-18 Thread Jeff Newmiller
What a mess. Transposing factors is highly unlikely to lead to sensible results. Did you look at str( x123 ) as your example created it? x <- data.frame( a=c(1,2,3), b=c("1","2","3"), stringsAsFactors=FALSE ) x123new <- setNames( as.data.frame( t( x[ , "b" ] ) ), paste( "b", 1:3, sep="_" ) )

[R] MACRO-LOOP in R

2016-02-18 Thread Amoy Yang via R-help
I am doing the data transpose with rename as shown below (step1 ~ step4) 1. Is any way in R similar to PROC TRANSPOSE used in SAS?2. How to use MACRO-LOOP to simplify the following procedure? THANK YOU FOR HELPS! # create data for test x<-data.frame(  a=c(1,2,3),  b=c("1","2","3")); x; str(x)#

Re: [R] for loop

2016-01-12 Thread Jim Lemon
Hi maryam (firoozi), Apart from the fact that you are overworking your sires (or the more realistic scenario of differential mating success) you can achieve the 700:30 ratio in this simple way: sires<-paste("Sire",1:30,sep="") dams<-paste("Dam",1:700,sep="")

Re: [R] for loop

2016-01-12 Thread Michael Dewey
Dear Maryam Please keep the list cc'ed in as others will have better answers than me. If dam has 700 members then sample (dam) gives you a random permutation of dams, each once. I did not understand the second part as i do not think you can have 30 sires each occurring 20 times. Did you

[R] for loop

2016-01-12 Thread maryam firoozi via R-help
Dear mr/madam I want to mak a matrix with 10 row and 3 column . this matrix is pedigree. my input sire<- c(1,2,3,4,5) count<- 0 sire<- cbind(sire,count) dam<- c(1,2,3,4,5,6,7,8,9,10) ped<-mstrix(NA,nrow=10,ncol=3) for(i in 1:10){ Sire<- sample(sire[,1],1) a<- which(sire[,1]==Sire)

Re: [R] for loop

2016-01-12 Thread Michael Dewey
Dear Maryam sample(dam) would give you a random permutation of dams sample(c(sire, sire)) would give you a random permutation of sires, each twice. Does that help? On 12/01/2016 05:53, maryam firoozi via R-help wrote: Dear mr/madam I want to mak a matrix with 10 row and 3 column . this

[R] For loop coding

2015-12-04 Thread Saba Sehrish via R-help
Hi I will be grateful if someone please tell me the programming to run regression on time series data through "For Loop". Regards. Saba Sent from Yahoo Mail on Android [[alternative HTML version deleted]] __ R-help@r-project.org mailing

Re: [R] For loop coding

2015-12-04 Thread PIKAL Petr
Hi > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Saba > Sehrish via R-help > Sent: Friday, December 04, 2015 11:21 AM > To: r-help@r-project.org > Subject: [R] For loop coding > > Hi > > I will be grateful if someone

Re: [R] for loop not working

2015-10-13 Thread mnw
Thank you for your comments. I guess what I need is to store movements and then loop through that matrix. Here is a snippet of the 'movement' code. I am trying to fill the matrix below with data from this loop. Is there something else my matrix (bottom) requires? Or its positioning? Many thanks,

Re: [R] for loop not working

2015-10-10 Thread David L Carlson
-Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon Sent: Saturday, October 10, 2015 6:04 AM To: mnw <ma...@aber.ac.uk> Cc: r-help mailing list <r-help@r-project.org> Subject: Re: [R] for loop not working Hi mnw, It looks to me as tho

Re: [R] for loop not working

2015-10-10 Thread Jim Lemon
ent.' The moment i make holder [[t]] it > works but just gives a list of '0's. I have tried many different things and > just cannot get it to work, so any help would be very much appreciated. > Again, sorry for the long post. > > > > > lst <- list() # temporary list to st

[R] for loop not working

2015-10-09 Thread mnw
ore the results for (i in seq(1, nrow(R) - 1)){ # loop through each row of the 'R' matrix lat1 <- deg2rad(R[i, 4]) long1 <- deg2rad(R[i, 5]) lat2 <- deg2rad(R[i + 1, 4]) long2 <- deg2rad(R[i + 1, 5]) gcd_vif <- gcd.vif(lat1, long1, lat2, long2) # calc estimated speed

[R-es] Loop for: mostrar el nombre de la variables

2015-06-30 Thread Griera
Buenos días: Después de más de 20 años en SAS, ahora igual me toca trabajar en R. Y la transición es muy dura: la lógica de los dos lenguajes es, para mi, totalmente diferente. Disculpen si lo que pregunto es una obviedad, pero llevo todo el día con esto y no logro encontrar la respuesta

Re: [R-es] Loop for: mostrar el nombre de la variables

2015-06-30 Thread Olivier Nuñez
Tengo dos problemas: 1. En: print (c(Var Num: , mean(XVARNUM))) no consigo que imprima el nombre de la variable ED después de Var Num:. En Internet parece que algunos sugieren utilizar: deparse(substitute(name(XVARNUM pero no me funciona. Utiliza cat: x=rnorm(100)

Re: [R-es] Loop for: mostrar el nombre de la variables

2015-06-30 Thread Griera-yandex
Hola Olivier: Muy elegante esta solución! Es lo que necesitaba. Gracias y saludos. On Tue, 30 Jun 2015 12:28:06 +0200 (CEST) Olivier Nuñez onu...@unex.es wrote: Un opción más elegante: DES = function(x) { res=NA if(is.numeric(x)) res=mean(x) else if(is.factor(x))

Re: [R-es] Loop for: mostrar el nombre de la variables

2015-06-30 Thread Olivier Nuñez
Bueno, te contesté rápido sin analizar mucho qué duda tenías con la gramática de R. He modificado tu función: DES = function(XDADES) { with(XDADES, for (XVARNUM in names(XDADES)) { if(is.numeric(get(XVARNUM))) { cat(Var Num:

Re: [R-es] Loop for: mostrar el nombre de la variables

2015-06-30 Thread Olivier Nuñez
Un opción más elegante: DES = function(x) { res=NA if(is.numeric(x)) res=mean(x) else if(is.factor(x)) { res - as.data.frame(table(x)) res - transform(res, cumFreq = cumsum(Freq), relative = prop.table(Freq))

Re: [R] for loop incorrect row count

2015-06-11 Thread David Winsemius
On Jun 11, 2015, at 12:25 PM, Kevin Kowitski wrote: Hey, I am having an issue with a for loop that is intended to read index values by row and column so that it can pull out the valuable information. My issue is that I am using a data.frame(which(df==1, arr.ind=TRUE)) That would be

[R] for loop incorrect row count

2015-06-11 Thread Kevin Kowitski
Hey,    I am having an issue with a for loop that is intended to read index values by row and column so that it can pull out the valuable information.  My issue is that I am using a data.frame(which(df==1, arr.ind=TRUE)) to find the index of the values in my data frame that are equal to 1.  

Re: [R] for loop incorrect row count

2015-06-11 Thread Bert Gunter
Oh, Swami, gazing into the crystal ball one can see ... ;-} Cheers, Bert Bert Gunter Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. -- Clifford Stoll On Thu, Jun 11, 2015 at 4:48 PM, David Winsemius dwinsem...@comcast.net wrote: On Jun 11,

Re: [R] for loop incorrect row count

2015-06-11 Thread John Kane
difficult. And which method I use can be a crap shoot. John Kane Kingston ON Canada -Original Message- From: dwinsem...@comcast.net Sent: Thu, 11 Jun 2015 16:48:40 -0700 To: k.kowit...@icloud.com Subject: Re: [R] for loop incorrect row count On Jun 11, 2015, at 12:25 PM, Kevin

Re: [R-es] Loop sobre muchos data frames

2015-04-13 Thread Jorge I Velez
Gracias, Oscar. Al parecer corresponde a un vector de caracteres. Puesto que lo que necesitamos es la informacion asociado a cada uno de esos nombres, creo que necesitas _leer_ la informacion que esta en cada uno de ellos. Por ejemplo, y - scan(bNames[1], what = 'character') y tendra la

Re: [R] break loop with keypress

2014-08-06 Thread William Simpson
Thanks Greg. I guess another option is to call a C function directly. On Windows I see there is a function _kbhit() in conio.h. Not sure if it would be that simple. Write a .c file #include conio.h int main(void) { int ch; ch= _kbhit(); return ch; } Then do the necessary stuff to call

[R] break loop with keypress

2014-08-05 Thread William Simpson
This works, but it is not quite what I need: par(mar=rep(0,4)) while(1) { img1-matrix(runif(2500),50,50) dev.hold(); image(img1,useRaster=TRUE); dev.flush() img2-matrix(runif(2500),50,50) dev.hold(); image(img2,useRaster=TRUE); dev.flush() } I would like to do this: while(!kbhit())

Re: [R] break loop with keypress

2014-08-05 Thread Greg Snow
You could create a tcltk window that looks for a button click and/or key press and when that happens change the value of a variable. Then in your loop you just look at the value of the same variable and break when the value changes. On Tue, Aug 5, 2014 at 6:13 AM, William Simpson

Re: [R] for loop using index values

2014-05-15 Thread arun
Hi, Not sure I understand correctly.  May be this helps: ##If the blocks are created as a list set.seed(475)  lst1 - setNames(lapply(1:10, function(i) {rowN - sample(20,1)*15; matrix(sample(40,10*rowN, replace=TRUE), nrow=rowN)}),1:10) sapply(lst1,nrow)100  #   1 2 3 4 5 6  

[R] for loop using index values

2014-05-14 Thread David Gwenzi
Hi all I have point data along a transect and I want to divide the transect into small blocks of 10m length each. I have named the blocks as a list i.e subset[[i]]. Now the issue is I want to process only those blocks that have at least 100 data points and keep the original index values of those

Re: [R] for loop using index values

2014-05-14 Thread David Winsemius
On May 14, 2014, at 9:23 PM, David Gwenzi wrote: Hi all I have point data along a transect and I want to divide the transect into small blocks of 10m length each. I have named the blocks as a list i.e subset[[i]]. Now the issue is I want to process only those blocks that have at least

Re: [R] for loop using index values

2014-05-14 Thread Frede Aakmann Tøgersen
-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: 15. maj 2014 06:49 To: David Gwenzi Cc: r-help@r-project.org Subject: Re: [R] for loop using index values On May 14, 2014, at 9:23 PM, David Gwenzi wrote: Hi all I have point data along a transect and I want to divide

Re: [R] for loop using index values

2014-05-14 Thread Frede Aakmann Tøgersen
Gwenzi [mailto:dgwe...@gmail.com] Sent: 15. maj 2014 07:43 To: Frede Aakmann Tøgersen Subject: Re: [R] for loop using index values Hi Frede, Thanks for your reple. I guess I am not making my question very clear. Sorry about that. Let me re-phrase it this way Suppose I have subSets

Re: [R] Simple Loop Counter

2014-04-26 Thread arun
, nrow = 26) # empty matrix n - 0 #set n to 0 for(i in letters) {   n - n+1   x[n,] - c(i, n) } x #*** #2. for (i in 1:10) { cat(loop, i, \n) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

[R] For loop processing too slow - pre-format data.frame?

2014-04-26 Thread cembling
Hi, I am bootstrapping, but my loops are taking way too long I need to make it faster. Looking on the R-help archive I suspect it may be due to not specifying the size of my data.frame, mainly because I don't know in advance how large it has to be. Can anyone help? My data looks like this

[R] for loop to list files

2014-04-21 Thread Beatriz R. Gonzalez Dominguez
Dear all, I'm trying to create a loop to select a series of files into my computer but I haven't been successful until now. I've looked into different possibilities but none has worked. I'd appretiate if you could help me by providing me with some ideas. Basically what I'd like to do is to

Re: [R] for loop to list files

2014-04-21 Thread Jorge I Velez
Hi Beatriz, Try paste(val_mapped_petpe_, 1976:1981, 01.txt, sep=) Best, Jorge.- On Mon, Apr 21, 2014 at 6:43 PM, Beatriz R. Gonzalez Dominguez aguitatie...@hotmail.com wrote: Dear all, I'm trying to create a loop to select a series of files into my computer but I haven't been successful

Re: [R] for loop to list files

2014-04-21 Thread Beatriz R. Gonzalez Dominguez
Hi Jorge, Thanks so much! Exactly what I wanted. Finally I wrote: for(i in 1976:1981){ PE.files_01_7681 - paste(val_mapped_petpe_, 1976:i, 01.txt, sep=) } Cheers, Bea On 21/04/2014 10:46, Jorge I Velez wrote: Hi Beatriz, Try paste(val_mapped_petpe_, 1976:1981, 01.txt, sep=) Best,

Re: [R] for loop to list files

2014-04-21 Thread Jeff Newmiller
You seem overly intent on getting a for loop into your code. Jorge's solution has the same effect as your for loop. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.us

Re: [R] Simple loop question

2014-03-29 Thread Noah Marconi
Here're a couple alternatives if you want to use the index instead of the variable name: # Reproducible data frame a1 - 1:15 a2 - letters[1:15] a3 - LETTERS[1:15] a4 - 15:1 a5 - letters[15:1] df - data.frame(a1, a2, a3, a4, a5) df # a1 a2 a3 a4 a5 # 1 1 a A 15 o # 2 2 b B 14 n # 3

[R] Simple loop question

2014-03-28 Thread Luana Marotta
Hi all, I'm trying to find out what is the equivalent in R for the following Stata code: Let's say I have the variables: a1, a2, a3, a4, a5 forvalues i = 1(1)5 { summary a`i' } That is, I want to know how to loop through variables in R. Thank you in advance, Luana [[alternative

Re: [R] Simple loop question

2014-03-28 Thread Jim Lemon
On 03/28/2014 05:27 PM, Luana Marotta wrote: Hi all, I'm trying to find out what is the equivalent in R for the following Stata code: Let's say I have the variables: a1, a2, a3, a4, a5 forvalues i = 1(1)5 { summary a`i' } That is, I want to know how to loop through variables in R. Hi

Re: [R] for loop with multiple conditions in R (e.g. for(i in x j in y)

2014-02-22 Thread arun
Hi, May be this helps: res.i - NULL  for(i in seq_along(x)){ res.i - c(res.i,x[i]-y[i])} #or using your nested loop: res.ij - NULL  for(i in seq_along(x)){  for(j in seq_along(y)){  if(i==j){  res.ij - c(res.ij,x[i]-y[j])  }  }} identical(x-y,res.i) #[1] TRUE identical(res.i,res.ij) #[1] TRUE

[R] for loop in R - strange behaviour

2014-01-29 Thread Supriya Jain
Hi, I notice the following from a for loop in R, which seems strange to me: When I do this: --- first - 0 nstep - 10 N - 14 while(first N) { print(--- ) last - first + nstep if(last N) last - N #start - first+2 for(i in (first+2):last)# line 11

Re: [R] for loop in R - strange behaviour

2014-01-29 Thread Duncan Murdoch
On 29/01/2014 11:32 AM, Supriya Jain wrote: Hi, I notice the following from a for loop in R, which seems strange to me: When I do this: --- first - 0 nstep - 10 N - 14 while(first N) { print(--- ) last - first + nstep if(last N) last - N #start - first+2 for(i

Re: [R] for loop in R - strange behaviour

2014-01-29 Thread Peter Alspach
-project.org Subject: [R] for loop in R - strange behaviour Hi, I notice the following from a for loop in R, which seems strange to me: When I do this: --- first - 0 nstep - 10 N - 14 while(first N) { print(--- ) last - first + nstep if(last N) last - N #start - first+2 for(i

Re: [R] For loop on column names

2014-01-18 Thread Frede Aakmann Tøgersen
Hi Try for (cname in colnames(mydf)) print((percent(length(is.null(mydf [, cname]) / lines)) Br. Frede Oprindelig meddelelse Fra: Jeff Johnson Dato:18/01/2014 02.10 (GMT+01:00) Til: R help Emne: [R] For loop on column names I'm trying to find a more efficient to calculate

Re: [R] For loop on column names

2014-01-18 Thread Bert Gunter
]) / lines)) Br. Frede Oprindelig meddelelse Fra: Jeff Johnson Dato:18/01/2014 02.10 (GMT+01:00) Til: R help Emne: [R] For loop on column names I'm trying to find a more efficient to calculate the percent a field is populated and repeat it for each field (column). First, I'm

[R] For loop on column names

2014-01-17 Thread Jeff Johnson
I'm trying to find a more efficient to calculate the percent a field is populated and repeat it for each field (column). First, I'm counting the number of lines: lines - as.integer(countLines(extract) - 1) dput(lines) 10L extract - 'C:/Users/jeffjohn/Desktop/batchextract_100k_sample.csv'

[R] For Loop Help

2014-01-05 Thread Mathew Nagendran
I'm relatively new to R. I'm trying to for loop but I keep getting an error message. Can anyone hint at what I am doing wrong please? m.control=c(1.45,9.40,9.96,4.2,1.86,0.2) m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09) t=function(m, a){(1-exp(-a*m))} #t function defined d=function(ts,

Re: [R] For Loop Help

2014-01-05 Thread Duncan Murdoch
On 14-01-05 3:47 PM, Mathew Nagendran wrote: I'm relatively new to R. I'm trying to for loop but I keep getting an error message. Can anyone hint at what I am doing wrong please? Nothing to do with the for loop. You have a call to your t function in which you don't specify a value for the a

Re: [R] For Loop Help

2014-01-05 Thread arun
Hi, I guess you need to change the parentheses from: ts=sum(t(m.sham),pick.a[count]) #to ts=sum(t(m.sham,pick.a[count])) #similarly for tc:  for(count in 1:length(pick.a)){  ts=sum(t(m.sham,pick.a[count]))  tc=sum(t(m.control,pick.a[count])) output[count,2] - (ts-tc)/ts  } A.K. On Sunday,

Re: [R] For loop for frequency counting

2014-01-02 Thread arun
Hi, May be this helps: var1 - ave(seq_along(fam),fam,FUN=length)  names(var1) - fam  var1 #2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 #4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 #or table(fam)[as.character(fam)] #fam #2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 #4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 fam1 - c(fam,2)  var2 -

[R] R for loop

2013-11-15 Thread matira
it take all the values of 'j' in each matrix. Thanks -- View this message in context: http://r.789695.n4.nabble.com/R-for-loop-tp4680515.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https

Re: [R] R for loop

2013-11-15 Thread David Carlson
Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of matira Sent: Friday, November 15, 2013 7:23 AM To: r-help@r-project.org Subject: [R] R for loop Hi I'm quite new to R and I am having trouble with this code: names

Re: [R] R for loop

2013-11-15 Thread Jeff Newmiller
to make it take all the values of 'j' in each matrix. Thanks -- View this message in context: http://r.789695.n4.nabble.com/R-for-loop-tp4680515.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https

Re: [R] R newbie - loop questions

2013-11-07 Thread Karl Schelhammer
and pass to my.function. Can someone else see what is wrong with this approach? /quote Quoted from: http://r.789695.n4.nabble.com/R-newbie-loop-questions-tp4679975.html _ Sent from http://r.789695.n4.nabble.com

Re: [R] R loop for applying an equation to each unique category

2013-11-04 Thread arun
. Hi all. I am seeking help in writing an R loop to calculate the shannon's information content (SIC) for every unique haplotype. The data includes the haplotypes in column 1 and frequency of haplotypes in column 2. As you can see in the example data with just 4 unique haplotypes

Re: [R] for loop help, repeat a function multiple times

2013-10-28 Thread arun
Hi, You may try: x - 1:5  set.seed(49)  mat1 - do.call(rbind,lapply(1:1000,function(y) sample(x,3))) #or mat2 - matrix(0,ncol=3,nrow=1000) set.seed(49)  for(i in seq_len(nrow(mat2))) mat2[i,] - sample(x,3) all.equal(mat1,mat2) #[1] TRUE #or set.seed(49) mat3 - t(replicate(1000,sample(x,3)))  

Re: [R] Looping over names of multiple data frames in an R for() loop XXXX

2013-10-13 Thread Mikkel Grum
frame names in an R for() loop. Can someone advise? miss-c(#NULL!,999) d-c(d1,d2,d3,d4) for(i in 1:4){ + + miss1-ifelse(i=2,miss[1],miss[2]) + miss1 + + get(d[i])-read.csv(paste(C:\\DATA\\Data\\Original\\,dsn[i],sep=), + na.strings=c(miss1,9)) + + head(get(d[i])) + + write.csv(get(d[i

Re: [R] Possible loop/ if statement query

2013-10-11 Thread PIKAL Petr
AM To: r-help@R-project.org Subject: [R] Possible loop/ if statement query Dear r genii, I hope you can help. I have vector 'b': b=c((1:10),sort(1:9,decreasing=TRUE),(2:12),sort(6:11,decreasing=TRUE), (7:13)) and, from 'b' I wish to create vector 'c': c=c( NA,NA,NA,NA,NA

[R] Looping over names of multiple data frames in an R for() loop XXXX

2013-10-11 Thread Dan Abner
Hi everybody, I thought I was using the get() fn correctly here to loop over multiple data frame names in an R for() loop. Can someone advise? miss-c(#NULL!,999) d-c(d1,d2,d3,d4) for(i in 1:4){ + + miss1-ifelse(i=2,miss[1],miss[2]) + miss1 + + get(d[i])-read.csv(paste(C:\\DATA\\Data

Re: [R] Looping over names of multiple data frames in an R for() loop XXXX

2013-10-11 Thread jim holtman
it. On Fri, Oct 11, 2013 at 2:59 PM, Dan Abner dan.abne...@gmail.com wrote: Hi everybody, I thought I was using the get() fn correctly here to loop over multiple data frame names in an R for() loop. Can someone advise? miss-c(#NULL!,999) d-c(d1,d2,d3,d4) for(i in 1:4){ + + miss1-ifelse(i=2,miss[1

Re: [R] Possible loop/ if statement query

2013-10-11 Thread Benjamin Gillespie
Sent: Thursday, October 10, 2013 12:39 AM To: r-help@R-project.org Subject: [R] Possible loop/ if statement query Dear r genii, I hope you can help. I have vector 'b': b=c((1:10),sort(1:9,decreasing=TRUE),(2:12),sort(6:11,decreasing=TRUE), (7:13)) and, from 'b' I wish to create vector

Re: [R] Possible loop/ if statement query

2013-10-10 Thread Benjamin Gillespie
To: Benjamin Gillespie Cc: R help Subject: Re: [R] Possible loop/ if statement query Hi, Try: b1- b b1[!b1=7]- NA lst1 - split(b1,cumsum(c(0,abs(diff(b=7) indx - as.logical(((seq_along(lst1)-1)%%2)) lst1[indx]- lapply(seq_along(lst1[indx]),function(i) {lst1[indx][[i]]- rep(i,length(lst1[indx

[R] Possible loop/ if statement query

2013-10-09 Thread Benjamin Gillespie
Dear r genii, I hope you can help. I have vector 'b': b=c((1:10),sort(1:9,decreasing=TRUE),(2:12),sort(6:11,decreasing=TRUE),(7:13)) and, from 'b' I wish to create vector 'c': c=c( NA,NA,NA,NA,NA,NA,1,1,1,1,1,1,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,2,2,2,2,2,2,2,2,2,2,2,NA,3,3,3,3,3,3,3)

Re: [R] Possible loop/ if statement query

2013-10-09 Thread arun
. - Original Message - From: arun smartpink...@yahoo.com To: Benjamin Gillespie gy...@leeds.ac.uk Cc: Sent: Wednesday, October 9, 2013 8:19 PM Subject: Re: [R] Possible loop/ if statement query Hi, There should be a simpler way with cumsum(diff()). b=c((1:10),sort(1:9,decreasing=TRUE

Re: [R] for loop of a geometric sequence

2013-09-04 Thread MacQueen, Don
So look at the examples found in ?Control and give it a try. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/30/13 9:57 AM, BJN1417 bjn1...@uncw.edu wrote: so I have to create a for loop of the geometric sequence

[R] for loop of a geometric sequence

2013-08-30 Thread BJN1417
so I have to create a for loop of the geometric sequence h(x,n)=1+x+x^2+x^3^4...x^n. I know that it would be easier to simply vectorize the sequence to x^(0:n), but I am required to make the loop, and I can't wrap my brain around how to loop it because the equation is so simple. -- View this

Re: [R] For loop output

2013-08-09 Thread Jenny Williams
: David Carlson [mailto:dcarl...@tamu.edu] Sent: 08 August 2013 18:04 To: Jenny Williams; r-help@r-project.org Subject: RE: [R] For loop output It's not clear how you are planning to use this within R, but you don't need a loop. individual.proj.quote - capture.output(write.table(matrix

Re: [R] For loop output

2013-08-09 Thread Jan Kim
: 995 -Original Message- From: David Carlson [mailto:dcarl...@tamu.edu] Sent: 08 August 2013 18:04 To: Jenny Williams; r-help@r-project.org Subject: RE: [R] For loop output It's not clear how you are planning to use this within R, but you

Re: [R] For loop output

2013-08-09 Thread David Carlson
-help@r-project.org Subject: RE: [R] For loop output To update on the use of this little string, I am trying to use it to automate files to be loaded into a raster stack. I think the issue I have with the string is related to the backslashes. I need to just read the pure text so that the datasets can

<    1   2   3   4   5   6   7   8   9   >