Re: [R] Loop over columns of dataframe and change values condtionally

2021-09-02 Thread Rui Barradas
Hello, In the particular case you have, to change to NA based on condition, use `is.na<-`. Here is some test data, 3 times the same df. set.seed(2021) df3 <- df2 <- df1 <- data.frame( x = c(0, 0, 1, 2, 3), y = c(1, 2, 3, 0, 0), z = rbinom(5, 1, prob = c(0.25, 0.75)), a =

Re: [R] Loop over columns of dataframe and change values condtionally

2021-09-02 Thread PIKAL Petr
Of Luigi Marongiu > Sent: Thursday, September 2, 2021 3:35 PM > To: r-help > Subject: [R] Loop over columns of dataframe and change values condtionally > > Hello, > it is possible to select the columns of a dataframe in sequence with: > ``` > for(i in 1:ncol(df)) { > df[

[R] Loop over columns of dataframe and change values condtionally

2021-09-02 Thread Luigi Marongiu
Hello, it is possible to select the columns of a dataframe in sequence with: ``` for(i in 1:ncol(df)) { df[ , i] } # or for(i in 1:ncol(df)) { df[ i] } ``` And change all values with, for instance: ``` for(i in 1:ncol(df)) { df[ , i] <- df[ , i] + 10 } ``` Is it possible to apply a

Re: [R] Loop for two columns and 154 rows

2020-09-16 Thread PIKAL Petr
t;https://www.precheza.cz/en/01-disclaimer/> https://www.precheza.cz/en/01-disclaimer/ From: Hesham A. AL-bukhaiti Sent: Tuesday, September 15, 2020 1:48 PM To: PIKAL Petr Subject: Re: [R] Loop for two columns and 154 rows thanks petr v much i attached my problem in word and my data

[R] Loop for two columns and 154 rows

2020-09-15 Thread Hesham A. AL-bukhaiti via R-help
Dears in R :i have this code in R: # this for do not work true (i tried )out<-read.csv("outbr.csv")  truth<-out[,seq(1,2)]truth<-cbind(as.character(truth[,1]),as.character(truth[,2])              ,as.data.frame(rep(0,,dim(out)[1])));for (j in 1:2) {  for (i in 1:20) {    truth[(truth[,1]==

Re: [R] Loop inside dplyr::mutate

2020-05-09 Thread Richard M. Heiberger
## I start with sim_data_wide sim_data_wide <- tidyr::spread(sim_data, quarter, pd) ## and calculate wide wide1 <- with(sim_data_wide, cbind(PC_1 = P_1, PC_2 = 1-(1-P_1)*(1-P_2), PC_3 = 1-(1-P_1)*(1-P_2)*(1-P_3), PC_4 =

Re: [R] Loop inside dplyr::mutate

2020-05-09 Thread Jeff Newmiller
Does this help? sim_wide2 <- ( sim_data %>% arrange( borrower_id, quarter ) %>% group_by( borrower_id ) %>% mutate( cumpd = 1 - cumprod( 1 - pd ) ) %>% ungroup() %>% mutate( qlbl = paste0( "PC_", quarter ) ) %>% select( borrower_id, qlbl, cumpd ) %>% spread( qlbl, cumpd ) ) On May 9, 2020

Re: [R] Loop inside dplyr::mutate

2020-05-09 Thread Fox, John
Dear Axel, Assuming that you're not wedded to using mutate(): > D1 <- 1 - as.matrix(sim_data_wide[, 2:11]) > D2 <- matrix(0, 10, 10) > colnames(D2) <- paste0("PC_", 1:10) > for (i in 1:10) D2[, i] <- 1 - apply(D1[, 1:i, drop=FALSE], 1, prod) > all.equal(D2, as.matrix(sim_data_wide[, 22:31])) [1]

[R] Loop inside dplyr::mutate

2020-05-09 Thread Axel Urbiz
Hello, Is there a less verbose approach to obtaining the PC_i variables inside the mutate? library(tidyverse) sim_data <- data.frame(borrower_id = sort(rep(1:10, 20)), quarter = rep(1:20, 10), pd = runif(length(rep(1:20, 10 # conditional probs

Re: [R] Loop With Dates

2019-09-24 Thread Greg Snow
Just to add one more option (which is best probably depends on if all the same dates are together in adjacent rows, if an earlier date can come later in the data frame, and other things): df$count <- cumsum(!duplicated(df$Date)) Skill a cumsum of logicals, just a different way of getting the

Re: [R] Loop With Dates

2019-09-22 Thread Richard O'Keefe
Is this what you're after? > df <- data.frame( + Date = as.Date(c("2018-03-29", "2018-03-29", "2018-03-29", + "2018-03-30", "2018-03-30", "2018- ..." ... [TRUNCATED] > df$count <- cumsum(c(TRUE, diff(df$Date) > 0)) > df Date count 1 2018-03-29 1 2

Re: [R] Loop With Dates

2019-09-21 Thread Jim Lemon
Hi Phillip, While I really like Ana's solution, this might also help: phdf<-read.table(text="Date count 2018-03-29 1 2018-03-29 1 2018-03-29 1 2018-03-30 1 2018-03-30 1 2018-03-30 1 2018-03-31 1 2018-03-31 1 2018-03-31 1",

Re: [R] Loop With Dates

2019-09-20 Thread Rui Barradas
Hello, Maybe I am not understanding but isn't this what you have asked in your previous question and my 2nd post (adapted) does? If not, where does it fail? Hope this helps, Rui Barradas Às 18:46 de 20/09/19, Phillip Heinrich escreveu: With the data snippet below I’m trying to increment

Re: [R] Loop With Dates

2019-09-20 Thread Ana PGG
== dates$lag)) + 1 dates$lag <- NULL > dates dates.object count 1 2018-03-29 1 2 2018-03-29 1 3 2018-03-29 1 4 2018-03-30 2 5 2018-03-30 2 6 2018-03-30 2 7 2018-03-31 3 8 2018-03-31 3 9 2018-03-31 3 De: Phillip Heinrich Enviado: vierne

[R] Loop With Dates

2019-09-20 Thread Phillip Heinrich
With the data snippet below I’m trying to increment the “count” vector by one each time the date changes. Date count 1 2018-03-29 1 2 2018-03-29 1 3 2018-03-29 1 81 2018-03-30 1 82 2018-03-30 1 83 2018-03-30 1 165 2018-03-31 1 166 2018-03-31 1

Re: [R] Loop Repetition

2019-08-06 Thread Tolulope Adeagbo
Wow...Great one BOB...Gracias, Merci. On Tue, 6 Aug 2019, 10:46 Bob O'Hara, wrote: > For a start, try this: > > for(i in 1:5) { > x <- runif(4,0,1) > } > > Which will do what you want, but will over-write x each time (so isn't > very good). Better (if you want to use the random numbers

Re: [R] Loop Repetition

2019-08-06 Thread Bob O'Hara
For a start, try this: for(i in 1:5) { x <- runif(4,0,1) } Which will do what you want, but will over-write x each time (so isn't very good). Better (if you want to use the random numbers outside the loop) is this: x <- matrix(NA, nrow=5, ncol=4) for(i in 1:5) { x[i,] <- runif(4,0,1) } But

Re: [R] Loop Repetition

2019-08-06 Thread Tolulope Adeagbo
Thanks guys, I've tried all you're suggesting, both for (x in 1:5) and break, but I cant seem to ascertain when the loop has generated a vector of 4 random numbers 5 times. On Tue, 6 Aug 2019, 10:09 Jim Lemon, wrote: > Hi Tolulope, > The "in" operator steps through each element of the vector

Re: [R] Loop Repetition

2019-08-06 Thread Jim Lemon
Hi Tolulope, The "in" operator steps through each element of the vector on the right. You only have one element. Therefore you probably want: for(x in 1:5) ... Jim Jim On Tue, Aug 6, 2019 at 6:54 PM Tolulope Adeagbo wrote: > > Hey guys, > > I'm trying to write a loop that will repeat an

Re: [R] Loop Repetition

2019-08-06 Thread Bob O'Hara
Is there anything wrong with just doing this? x <- runif(5, min = 0, max = 1) Also note that you use x to be at last 2 things: in for (x in 5) { you set it to 5, and then in the loop you x = runif(1:4, min = 0, max = 1) you make it a vector of length 4. You also fail to use break to stop

[R] Loop Repetition

2019-08-06 Thread Tolulope Adeagbo
Hey guys, I'm trying to write a loop that will repeat an action for a stipulated number of times. I have written some code but i think i'm missing something. for (x in 5) { repeat{ x = runif(1:4, min = 0, max = 1) print(x) if (x== var_1[5]){ print("done") }

Re: [R] loop through columns in a data frame

2019-03-26 Thread Yuan, Keming (CDC/DDNID/NCIPC/DVP) via R-help
Thank you so much, Jim. That’s exactly what I need. Sorry for not providing the data frame. But you created the correct data structure. Thanks again! From: jim holtman Sent: Monday, March 25, 2019 2:07 PM To: Yuan, Keming (CDC/DDNID/NCIPC/DVP) Cc: R-help@r-project.org Subject: Re: [R] loop

Re: [R] loop through columns in a data frame

2019-03-25 Thread Bert Gunter
"Does anyone know how to use loop (or other methods) to create new columns? In SAS, I can use array to get it done. But I don't know how to do it in R." Yup. Practically all users of R know how, as this is entirely elementary. You will too if you make the effort to go through a basic R tutorial,

Re: [R] loop through columns in a data frame

2019-03-25 Thread jim holtman
R Notebook You forgot to provide what your test data looks like. For example, are all the columns a single letter followed by “_" as the name, or are there longer names? Are there always matched pairs (‘le’ and ‘me’) or can singles occur? Hide library(tidyverse)# create some data test <-

[R] loop through columns in a data frame

2019-03-25 Thread Yuan, Keming (CDC/DDNID/NCIPC/DVP) via R-help
Hi All, I have a data frame with variable names like A_le, A_me, B_le, B_me, C_le, C_me if A_le=1 or A_me=1 then I need to create a new column A_new=1. Same operation to create columns B_new, C_new... Does anyone know how to use loop (or other methods) to create new columns? In SAS, I can

Re: [R] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Marna Wagley
me.mat[, > > column]]),3,TRUE))) > > > > } > > > > > get(samplenames[1]) > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] > > year224 0.556 0.667 0.571 0.526 0.629 0.696 0.323 0.526 0.256 0.667 > > year142 0.324 0.324 0.7

Re: [R] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Jim Lemon
6 0.256 0.667 > year142 0.324 0.324 0.706 0.638 0.600 0.294 0.612 0.688 0.432 0.387 > year237 0.571 0.696 0.629 0.471 0.462 0.471 0.452 0.595 0.333 0.435 > > > > > -- > *From:* Jim Lemon > *Sent:* September 11, 2018 1:44 AM > *To:* Kristi Glover

Re: [R] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Kristi Glover
.333 0.435 From: Jim Lemon Sent: September 11, 2018 1:44 AM To: Kristi Glover Cc: r-help mailing list Subject: Re: [R] loop for comparing two or more groups using bootstrapping Hi Kristy, Try this: colname.mat<-combn(paste0("year",1:4),2) samplenames

Re: [R] loop for comparing two or more groups using bootstrapping

2018-09-11 Thread Jim Lemon
Hi Kristy, Try this: colname.mat<-combn(paste0("year",1:4),2) samplenames<-apply(colname.mat,2,paste,collapse="") k<-1 for(column in 1:ncol(colname.mat)) { assign(samplenames[column],replicate(k,sample(unlist(daT[,colname.mat[,column]]),3,TRUE))) } Then use get(samplenames[1]) and so on to

Re: [R] loop over matrix: subscript out of bounds

2018-08-08 Thread Rui Barradas
Hello, There are now three solutions to the OP's problem. I have timed them and the results depend on the matrix size. The solution I thought would be better, Enrico's diag(), is in fact the slowest. As for the other two, Eric's for loop is 50% fastest than the matrix index for small matrices

Re: [R] loop over matrix: subscript out of bounds

2018-08-08 Thread S Ellison
> > Eric Bergeron Wed, 8 Aug 2018 12:53:32 +0300 writes: > > > You only need one "for loop" > > for(i in 2:nrow(myMatrix)) { > >myMatrix[i-1,i-1] = -1 > >myMatrix[i-1,i] = 1 > > } Or none, with matrix-based array indexing and explicit control of the indices to prevent overrun

Re: [R] loop over matrix: subscript out of bounds

2018-08-08 Thread Martin Maechler
> Eric Bergeron Wed, 8 Aug 2018 12:53:32 +0300 writes: > You only need one "for loop" > for(i in 2:nrow(myMatrix)) { >myMatrix[i-1,i-1] = -1 >myMatrix[i-1,i] = 1 > } > > HTH, > Eric and why are you not using Enrico Schumann's even nicer solution (from August 6) that I had

Re: [R] loop over matrix: subscript out of bounds

2018-08-08 Thread Maija Sirkjärvi
Thanks a lot ! That's it! Maija ke 8. elok. 2018 klo 12.53 Eric Berger (ericjber...@gmail.com) kirjoitti: > You only need one "for loop" > > for(i in 2:nrow(myMatrix)) { >myMatrix[i-1,i-1] = -1 >myMatrix[i-1,i] = 1 > } > > HTH, > Eric > > > On Wed, Aug 8, 2018 at 12:40 PM, Maija

Re: [R] loop over matrix: subscript out of bounds

2018-08-08 Thread Eric Berger
You only need one "for loop" for(i in 2:nrow(myMatrix)) { myMatrix[i-1,i-1] = -1 myMatrix[i-1,i] = 1 } HTH, Eric On Wed, Aug 8, 2018 at 12:40 PM, Maija Sirkjärvi wrote: > Thanks! > > If I do it like this: > > myMatrix <- matrix(0,5,5*2-3) > print(myMatrix) > for(i in 2:nrow(myMatrix))

Re: [R] loop over matrix: subscript out of bounds

2018-08-08 Thread Maija Sirkjärvi
Thanks! If I do it like this: myMatrix <- matrix(0,5,5*2-3) print(myMatrix) for(i in 2:nrow(myMatrix)) for(j in 2:ncol(myMatrix)) myMatrix[i-1,j-1] = -1 myMatrix[i-1,j] = 1 print(myMatrix) I get the following result: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] -1 -1 -1 -1 -1

Re: [R] loop over matrix: subscript out of bounds

2018-08-07 Thread Rui Barradas
Hello, If it is not running as you want it, you should say what went wrong. Post the code that you have tried and the expected output, please. (In fact, the lack of expected output was the reason why my suggestion was completely off target.) Rui Barradas On 07/08/2018 09:20, Maija Sirkjärvi

Re: [R] loop over matrix: subscript out of bounds

2018-08-07 Thread Maija Sirkjärvi
Thanks, but I didn't quite get it. And I don't get it running as it should. ti 7. elok. 2018 klo 10.47 Martin Maechler (maech...@stat.math.ethz.ch) kirjoitti: > > > Thanks for help! > > However, changing the index from i to j for the column vector changes the > > output. I would like the matrix

Re: [R] loop over matrix: subscript out of bounds

2018-08-07 Thread Martin Maechler
> Thanks for help! > However, changing the index from i to j for the column vector changes the > output. I would like the matrix to be the following: > -1 1 0 0 0 0 0 > 0 -1 1 0 0 0 0 > 0 0 -1 1 0 0 0 > . > etc. > How to code it? as Enrico Schumann showed you: Without any loop, a very

Re: [R] loop over matrix: subscript out of bounds

2018-08-07 Thread Maija Sirkjärvi
Thanks for help! However, changing the index from i to j for the column vector changes the output. I would like the matrix to be the following: -1 1 0 0 0 0 0 0 -1 1 0 0 0 0 0 0 -1 1 0 0 0 . etc. How to code it? Best, Maija >> myMatrix <- matrix(0,5,12) >> for(i in 1:nrow(myMatrix)) { >>

Re: [R] loop over matrix: subscript out of bounds

2018-08-06 Thread Rui Barradas
Hello, Eric is right but... You have two assignments. The second sets a value that will be overwritten is the next iteration by myMatrix[i,i] = -1 when 'i' becomes the next value. If you fix the second index and use 'j', you might as well do myMatrix[] = -1 myMatrix[, ncol(myMatrix)] = 1

Re: [R] loop over matrix: subscript out of bounds

2018-08-06 Thread Enrico Schumann
Quoting Maija Sirkjärvi : I have a basic for loop with a simple matrix. The code is doing what it is supposed to do, but I'm still wondering the error "subscript out of bounds". What would be a smoother way to code such a basic for loop? myMatrix <- matrix(0,5,12) for(i in 1:nrow(myMatrix))

Re: [R] loop over matrix: subscript out of bounds

2018-08-06 Thread Eric Berger
Both loops are on 'i', which is a bad idea. :-) Also myMatrix[i,i+1] will be out-of-bounds if i = ncol(myMatrix) On Mon, Aug 6, 2018 at 12:02 PM, Maija Sirkjärvi wrote: > I have a basic for loop with a simple matrix. The code is doing what it is > supposed to do, but I'm still wondering the

[R] loop over matrix: subscript out of bounds

2018-08-06 Thread Maija Sirkjärvi
I have a basic for loop with a simple matrix. The code is doing what it is supposed to do, but I'm still wondering the error "subscript out of bounds". What would be a smoother way to code such a basic for loop? myMatrix <- matrix(0,5,12) for(i in 1:nrow(myMatrix)) { for(i in 1:ncol(myMatrix))

Re: [R] Loop Function to Create Multiple Scatterplots

2018-05-21 Thread MacQueen, Don
Here is a simplified example: dat <- data.frame(x=1:4, y1=runif(4), y2=runif(4), y3=4:1) for (icol in 2:4) plot(dat[,1] , dat[,icol] ) (not tested, so hopefully all my parentheses are balanced, no typos, etc.) This shows the basic principle. An alternative is to construct each column name as

Re: [R] Loop Function to Create Multiple Scatterplots

2018-05-21 Thread John Kane via R-help
As Jim says, "No data". R-help is very fussy about what files it will accept.  You might try changing the extention to txt.  However the preferred way here is to use the dput() command and paste the results into the post.  See ?dput for details. On Monday, May 21, 2018, 1:40:59 a.m.

Re: [R] Loop Function to Create Multiple Scatterplots

2018-05-21 Thread Jim Lemon
Hi Steven, Sad to say that your CSV file didn't make it to the list and I can't access the data via your Dropbox account. Therefore we don't know the structure of "mydata". If you are able to plot the data as in your example, this might help: genexp<-matrix(runif(360,1,2),ncol=18)

[R] Loop Function to Create Multiple Scatterplots

2018-05-20 Thread STEVEN MANCINI
Hello, I am trying to create multiple scatter plot graphs. I have 1 independent variable (Age - weeks post conception) and 18 dependent variables ("Gene n" Expression) in one csv file. Is there a way to set up a looped function to produce 18 individual scatterplots? At the moment, I am writing

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] loop with variable names

2016-11-05 Thread Bert Gunter
1. Statistically, you probably don't want to do this at all (but that's another story). 2. Programatically, you probably want to use one of several packages that do it already rather than trying to reinvent the wheel. A quick search on rseek.org for "all subsets regression" brought up this:

Re: [R] loop with variable names

2016-11-04 Thread Ista Zahn
It's hard to imagine a situation where this makes sense, but of course you can do it if you want. Perhaps rhs <- unlist(sapply(1:(ncol(df)-1), function(x) apply(combn(names(df)[-1], x), 2, paste, collapse = " + "))) lapply(rhs, function(x) lm(as.formula(paste("y ~", x)), data = df)) --Ista On

[R] loop with variable names

2016-11-04 Thread paolo brunori
Suppose I have the following data: y<-rnorm(10) age<-rnorm(10) sex<-rbinom(10,1, 0.5) edu<-round(runif(10, 1, 20)) edu2<-edu^2 df<-data.frame(y,age,sex,edu,edu2) I want to run a large number of models, for example: lm(y~age) lm(y~age+sex) lm(y~age+sex+edu) lm(y~age+sex+edu+edu2)

Re: [R] Loop to check for large dataset

2016-10-10 Thread Adrian Dușa
00 1 1 > > 117 117 1 1 > > 148 148 1 1 > > > > Cheers > > Petr > > > > > > *From:* dusa.adr...@gmail.com [mailto:dusa.adr...@gmail.com] *On Behalf > Of *Adrian Du?a > *Sent:* Monday, October 10, 2016 12:26 PM > *To:* Christoph Puschmann <c.puschm...@st

Re: [R] Loop to check for large dataset

2016-10-10 Thread PIKAL Petr
il.com [mailto:dusa.adr...@gmail.com] On Behalf Of Adrian Du?a Sent: Monday, October 10, 2016 12:26 PM To: Christoph Puschmann <c.puschm...@student.unsw.edu.au> Cc: r-help@r-project.org; PIKAL Petr <petr.pi...@precheza.cz> Subject: Re: [R] Loop to check for large dataset This is an example of how a

Re: [R] Loop to check for large dataset

2016-10-10 Thread Adrian Dușa
This is an example of how a reproducible code looks like, assuming you have three columns in your dataset named S (store), P (product) and W (week), and also assuming they have integer values from 1 to 19, 1 to 22 and 1 to 157 respectively: # mydata <- expand.grid(seq(19), seq(22),

Re: [R] Loop to check for large dataset

2016-10-10 Thread PIKAL Petr
ull set STORE, WEEK and description and merge it with original data by merge. Cheers Petr From: Christoph Puschmann [mailto:c.puschm...@student.unsw.edu.au] Sent: Monday, October 10, 2016 9:34 AM To: PIKAL Petr <petr.pi...@precheza.cz>; r-help@r-project.org Subject: Re: [R] Loop to check

Re: [R] Loop to check for large dataset

2016-10-10 Thread Christoph Puschmann
Dear Petr, I attached a sample file, which contains the first 4 products. It is more that I have: 157 weeks, 19 different Stores and 22 products: 157*19*22 = 65,626 rows. And as I sated I have roughly 63,127 rows. (so some have to be missing). All the best, Christoph

Re: [R] Loop to check for large dataset

2016-10-10 Thread PIKAL Petr
.puschm...@student.unsw.edu.au> > Subject: Re: [R] Loop to check for large dataset > > Dear Adrian, > > Yes it is a cyclical data set and theoretically it should repeat this > interval until > 61327. The data set itself is divided into 2 Parts: > 1. Product category (

Re: [R] Loop to check for large dataset

2016-10-08 Thread Christoph Puschmann
Dear Adrian, Yes it is a cyclical data set and theoretically it should repeat this interval until 61327. The data set itself is divided into 2 Parts: 1. Product category (column 10) 2. Number of Stores Participating (column 01) Overall there are 22 different products and in each you have 19

Re: [R] Loop to check for large dataset

2016-10-08 Thread Adrian Dușa
It would help to have a minimal, reproducible example. Unless revealing the structure of your FD object, it is difficult to understand how a column having 61327 values would be "consistent over an 1 to 157 interval": is this interval cyclic until it reaches 61327 values? >From your example using

Re: [R] Loop to check for large dataset

2016-10-08 Thread ruipbarradas
Hello, I'm not at all sure if the following is what you need but instead of for (i in length(FD$WEEK)) try for (i in 1:length(FD$WEEK)) or even better for (i in seq_len(FD$WEEK)) And use Control[i, 1], not Control[, 1] Hope thi helps, Rui Barradas Citando Christoph Puschmann

[R] Loop to check for large dataset

2016-10-08 Thread Christoph Puschmann
Hey all, I would like to know if anyone, can put in the right direction of the following problem: I am currently want to use it to check if a column with a length of 61327 is consistent over an 1 to 157 interval until the end of the column. In the case the interval is interrupted I want to

Re: [R] Loop over rda list files and using the attach function

2016-09-01 Thread Juan Ceccarelli Arias
Hi I want to comment something. When i added the detach(get(yyz)) the RAM consumption was considerable reduced. So, i want to declare this issue as solved and thank you all for your assistance. Good luck to all. On Tue, Aug 30, 2016 at 6:24 PM, Juan Ceccarelli Arias wrote: >

Re: [R] Loop over rda list files and using the attach function

2016-08-30 Thread Juan Ceccarelli Arias
The attach(get(yyz)) option i tried and it worked. The only issue, is that when i'm trying to export the results, it takes a lot of time. Considerably more than Stata. Also, the computer almost collapses for a task which isn't so exhausting for my PC station. Im dubious... On Tue, Aug 30, 2016

Re: [R] Loop over rda list files and using the attach function

2016-08-30 Thread ruipbarradas
Hello, Try attach(get(yyz)) Hope this helps, Rui Barradas Citando Juan Ceccarelli Arias : Hi. I need to loop over rda files. I generated the list of them. That's ok. The problem is that the name of the files are as _mm (eg 2010_01 is january or 2010, 2016_03 is

Re: [R] Loop over rda list files and using the attach function

2016-08-30 Thread Greg Snow
You can attach rda files directly with the attach function, no need to load them first (see the what argument in the help for attach). This may do what you want more directly. In general it is better to not use loops and attach for this kind of thing. It is better to store multiple data objects

Re: [R] Loop over rda list files and using the attach function

2016-08-30 Thread Jorge Cimentada
Here's the problem: when you load the object and name it yyz, its simply storing the name of the data frame as a string. Naturally, when you you attach the string, it throws an error. The loop actually loads the data frame but inside yyz there's not a data frame. One problem with load() is that

[R] Loop over rda list files and using the attach function

2016-08-30 Thread Juan Ceccarelli Arias
Hi. I need to loop over rda files. I generated the list of them. That's ok. The problem is that the name of the files are as _mm (eg 2010_01 is january or 2010, 2016_03 is march of 2016). So, when i try to use the attach function to create a simple table(age, sex) it fails. The only way to

Re: [R] Loop over folder files

2016-08-24 Thread Juan Ceccarelli Arias
Ok. Please, declare this issue as solved. And thanks again for your help. On Wed, Aug 24, 2016 at 2:18 PM, wrote: > Maybe it's better to open a new thread. > > Rui Barradas > > > Citando Juan Ceccarelli Arias : > > The error wasn't in the loop. It was in

Re: [R] Loop over folder files

2016-08-24 Thread Juan Ceccarelli Arias
The error wasn't in the loop. It was in the file list. It's running now because i added full.names option to TRUE fuente=list.files("C:/Users/Jceccarelli/Bases/Stata", pattern="dta$", full.names=T) Now R can proccess the data. Now it callapses or stops because other kind of error. ¿Should i open

Re: [R] Loop over folder files

2016-08-24 Thread ruipbarradas
Maybe it's better to open a new thread. Rui Barradas   Citando Juan Ceccarelli Arias : > The error wasn't in the loop. It was in the file list. > It's running now because i added full.names option to TRUE > fuente=list.files("C:/Users/Jceccarelli/Bases/Stata", >

Re: [R] Loop over folder files

2016-08-24 Thread Juan Ceccarelli Arias
I just doesn't work... Im loading the read,dta13 package already. When i try to perform a simple table(sex), i received the "File not found" message. However, if i load the data using the file.choose() option inside read.dta13, i can open the stata file. I don't know what am i doing wrong... On

Re: [R] Loop over folder files

2016-08-24 Thread ruipbarradas
Hello, That means that probably the files are in a different folder/directory. Use getwd() to see what is your current directory and setwd("path/to/files") to set the right place where the files can be found. Rui Barradas   Citando Juan Ceccarelli Arias : > I just doesn't

Re: [R] Loop over folder files

2016-08-23 Thread ruipbarradas
Or maybe a print() statement on the table() in the loop. print(table(...)) Rui Barradas   Citando David Winsemius : >> On Aug 23, 2016, at 10:01 AM, Juan Ceccarelli Arias >> wrote: >> >> Im running this but the code doesn't seem work. >> It just

Re: [R] Loop over folder files

2016-08-23 Thread MacQueen, Don
Compare what happens with these two command: for (i in 1:3) { table(letters[1:4]) } for (i in 1:3) { print(table(letters[1:4])) } Then try modifying your loop similarly. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On

Re: [R] Loop over folder files

2016-08-23 Thread ruipbarradas
Hello, Where does read_dta come from? You should also post the library() instruction. Try to run the code without the loop, with just one file and inspect xxx to see what's happening. xxx <- read_dta(fuente[1]) str(xxx) table(xxx$cise, xxx$sexo) Rui Barradas   Citando Juan Ceccarelli Arias

Re: [R] Loop over folder files

2016-08-23 Thread David Winsemius
> On Aug 23, 2016, at 10:01 AM, Juan Ceccarelli Arias wrote: > > Im running this but the code doesn't seem work. > It just hangs out but doesn't show any error. > > > for (i in 1:length(fuente)){ > > xxx=read_dta(fuente[i]) > > table(xxx$cise, xxx$sexo) > > rm(xxx) > >

Re: [R] Loop over folder files

2016-08-23 Thread Juan Ceccarelli Arias
Im running this but the code doesn't seem work. It just hangs out but doesn't show any error. for (i in 1:length(fuente)){ xxx=read_dta(fuente[i]) table(xxx$cise, xxx$sexo) rm(xxx) } On Tue, Aug 23, 2016 at 6:31 AM, wrote: > Hello, > > The op could also use package

Re: [R] Loop over folder files

2016-08-23 Thread ruipbarradas
Hello, The op could also use package sos to find that and other packages to read stata files. install.packages("sos") library(sos) findFn("stata") found 374 matches;  retrieving 19 pages 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Downloaded 258 links in 121 packages The first package is

Re: [R] Loop over folder files

2016-08-23 Thread Michael Dewey
Dear Juan If this is a Stata 13 file the package readstata13 available from CRAN may be of assistance. On 22/08/2016 18:40, Juan Ceccarelli Arias wrote: I removed the data,frame=True... I obtain this warnings... Error in read.dta(fuente[i]) : not a Stata version 5-12 .dta file In addition:

Re: [R] Loop over folder files

2016-08-22 Thread David Winsemius
> On Aug 22, 2016, at 10:40 AM, Juan Ceccarelli Arias wrote: > > I removed the data,frame=True... > I obtain this warnings... > Error in read.dta(fuente[i]) : not a Stata version 5-12 .dta file Well, that seems fairly self-explanatory. What version of Stata are you using

Re: [R] Loop over folder files

2016-08-22 Thread Juan Ceccarelli Arias
I removed the data,frame=True... I obtain this warnings... Error in read.dta(fuente[i]) : not a Stata version 5-12 .dta file In addition: There were 50 or more warnings (use warnings() to see the first 50) the warnings() throws this Warning messages: 1: In `levels<-`(`*tmp*`, value = if (nl ==

Re: [R] Loop over folder files

2016-08-22 Thread ruipbarradas
Hello, That argument doesn't exist, hence the error. Read the help page ?read.dta more carefully. You will see that already read.dta reads into a data.frame. Hope this helps, Rui Barradas   Citando Juan Ceccarelli Arias : > Hi > I need to apply some code over some stata

[R] Loop over folder files

2016-08-22 Thread Juan Ceccarelli Arias
Hi I need to apply some code over some stata files that are in folder. I've wrote this library(foreign) fuente=list.files("C:/Users/Jceccarelli/Bases/Stata", pattern="dta$", full.names=FALSE) for (i in 1:length(fuente)){ xxx=read.dta(fuente[i], to.data.frame=TRUE) } But i get this error

Re: [R] loop function

2016-08-18 Thread Adams, Jean
You seemed to have re-written over the "b" object in your code. This might work for you. library(MASS) for (i in 58:1){ for(j in 58:i){ str.temp <- paste("y1 ~ x", i, "* x", j, sep = "") univar <- glm.nb(as.formula(str.temp), data=df) b <- summary(univar)$coeffients[4, 4] if(b <

[R] loop function

2016-08-18 Thread fatimah soleimany
Hi Dear users, for an interactive use, i am trying to write a loop that looks for all variables in the conditions which i introduced, this is what I'm trying: library(MASS)> i=1> for (i in 58:1){+ for(j in 58:i){+ + str.temp <- paste("y1 ~ x", i, "* x", j, sep = "")+

Re: [R] loop testing unidentified columns

2016-06-20 Thread Brittany Demmitt
essage- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Brittany > Demmitt > Sent: Monday, June 20, 2016 12:15 PM > To: r-help@r-project.org > Subject: [R] loop testing unidentified columns > > Hello, > > I want to compare all of the columns of one data

Re: [R] loop testing unidentified columns

2016-06-20 Thread David L Carlson
3 - David L Carlson Department of Anthropology Texas A University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Brittany Demmitt Sent: Monday, June 20, 2016 12:15 PM To: r-help@r-project.org Subject: [R] loop test

[R] loop testing unidentified columns

2016-06-20 Thread Brittany Demmitt
Hello, I want to compare all of the columns of one data frame to another to see if any of the columns are equivalent to one another. The first column in both of my data frames are the sample IDs and do not need to be compared. Below is an example of the loop I am using to compare the two data

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] Loop Help

2016-02-29 Thread David Winsemius
> On Feb 29, 2016, at 6:24 AM, Fernando McRayearth wrote: > > Need to create ascii maps for 10 species by writing a loop. So i have to have > the vectors ready in the Global Environment, and the "raster map" so the > information can be added. > > when writing the loop I

[R] Loop Help

2016-02-29 Thread Fernando McRayearth
Need to create ascii maps for 10 species by writing a loop. So i have to have the vectors ready in the Global Environment, and the "raster map" so the information can be added. when writing the loop I am using the "paste" function because the only thing that changes in the vector is the name

Re: [R] Loop over regression results

2015-02-17 Thread Ronald Kölpin
Thank you David and Thierry, your answers helped a lot! Kind regards, RK. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] Loop over regression results

2015-02-16 Thread Thierry Onkelinx
virginica 0.6314052 0.1428938 4.418702 5.647610e-05 David C -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David L Carlson Sent: Monday, February 16, 2015 8:52 AM To: Ronald Kölpin; r-help@r-project.org Subject: Re: [R] Loop over regression

[R] Loop over regression results

2015-02-16 Thread Ronald Kölpin
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dear all, I have a problem when trying to present the results of several regression. Say I have run several regressions on a dataset and saved the different results (as in the mini example below). I then want to loop over the regression results in

Re: [R] Loop over regression results

2015-02-16 Thread David L Carlson
Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ronald Kölpin Sent: Monday, February 16, 2015 7:37 AM To: r-help@r-project.org Subject: [R] Loop over regression results

Re: [R] Loop over regression results

2015-02-16 Thread David L Carlson
4.418702 5.647610e-05 David C -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David L Carlson Sent: Monday, February 16, 2015 8:52 AM To: Ronald Kölpin; r-help@r-project.org Subject: Re: [R] Loop over regression results In R you would want to combine

Re: [R] Loop with ggplot2 not as simple as it seems...

2014-10-29 Thread PIKAL Petr
() } Cheers Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Patricia Seo Sent: Tuesday, October 28, 2014 1:59 AM To: r-help@r-project.org Subject: [R] Loop with ggplot2 not as simple as it seems... Hi everyone, I

[R] Loop with ggplot2 not as simple as it seems...

2014-10-27 Thread Patricia Seo
Hi everyone, I have been battling with this problem for the past month and reading all that I can about it, but I just can't seem to understand what I'm doing wrong. It seems easy and I can replicate others well-recorded attempts, but can not seem to apply this to my data. I have created a

  1   2   3   4   5   6   7   >