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 = letters[1:5]

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

2021-09-02 Thread PIKAL Petr
Hi you could operate with whole data frame (sometimes) head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2

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

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 = 1-(1-P_1

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 4:4

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]

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 logi

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 2018

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", header=TRUE,strings

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 the

Re: [R] Loop With Dates

2019-09-20 Thread Ana PGG
Hi Phillip, This can be done in several ways as most things in programming. Here is one posible solution: dates <- c("2018-03-29", "2018-03-29", "2018-03-29", "2018-03-30", "2018-03-30", "2018-03-30", "2018-03-31", "2018-03-31", "2018-03-31") dates <- as.data.frame(as.Dat

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 outside

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 o

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 action

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 the

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, o

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 <- tibble(a

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

2018-09-11 Thread Marna Wagley
colname.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.32

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

2018-09-11 Thread Jim Lemon
0.526 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 G

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 i

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 mention

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 Sirkjärv

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 w

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 t

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 nic

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 H

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 err

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 a

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. EDT

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) colnames(genexp)

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: http:

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 Fr

Re: [R] Loop to check for large dataset

2016-10-10 Thread Adrian Dușa
8 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 > *Cc:* r-help@r-project.org; PIKAL Petr &g

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 Cc: r-help@r-project.org; PIKAL Petr Subject: Re: [R] Loop to check for large dataset This is an example of how a reproducible code looks like, assuming you have three columns i

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), seq(15

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 ; r-help@r-project.org Subject: Re: [R] Loop to check for large dataset Dear Petr,

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
Hi see in line > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christoph > Puschmann > Sent: Sunday, October 9, 2016 1:27 AM > To: Adrian Dușa > Cc: r-help@r-project.org; Christoph Puschmann > > Subject: Re: [R] Loop to

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 diffe

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 F

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 : Hey

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: > The attach(get(yyz))

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 at

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 march of 2016). So,

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 yo

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 the file list. > It's running now because

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 an

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", > pattern="dta$", full.names=T) >

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 Tu

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 work... > Im loading 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 hangs out but doesn't show any error. >> >> fo

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 8/2

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) > > } I still find the

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 sos to find that and oth

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

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: Th

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 and does it have capac

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 == 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 files that are in fol

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 <

Re: [R] loop testing unidentified columns

2016-06-20 Thread Brittany Demmitt
Thank you! > On Jun 20, 2016, at 12:41 PM, David L Carlson wrote: > > It does not test the first column, but a vector must have consecutive > indices. Since you did not assign a value, R inserts a missing value. If you > don't want to see it use > >> results.pc.all[, -1] > [,1] [,2]

Re: [R] loop testing unidentified columns

2016-06-20 Thread David L Carlson
It does not test the first column, but a vector must have consecutive indices. Since you did not assign a value, R inserts a missing value. If you don't want to see it use > results.pc.all[, -1] [,1] [,2] results.212 results.323 - Da

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 am using the "paste"

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 http://www.R-project.org/postin

Re: [R] Loop over regression results

2015-02-16 Thread Thierry Onkelinx
or 1.0536478 0.1712595 6.152348 1.41e-07 > 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 &

Re: [R] Loop over regression results

2015-02-16 Thread David L Carlson
inica 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 results In R y

Re: [R] Loop over regression results

2015-02-16 Thread David L Carlson
In R you would want to combine the results into a list. This could be done when you create the regressions or afterwards. To repeat your example using a list: data(iris) taxon <- levels(iris$Species) mod <- lapply(taxon, function (x) lm(Sepal.Width ~ Petal.Width, data=iris, subset=Specie

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

2014-10-29 Thread PIKAL Petr
Hi Patricia You are somewhat circling around solution. Is this what you wanted? for (i in 5:7) { plotname = paste("Graph", names(scores)[i], sep="") png(paste0(plotname,".png")) p <- ggplot(scores, aes(x=scores[,i], fill=gender )) print(p+ geom_density(alpha=.3)+xlab(names(scores)[i])) d

Re: [R] loop

2014-10-05 Thread jim holtman
Please don't post in HTML since your code was all messed up. You did not mention what problems you were having with your code. Now a couple of things to check is to look at what the structure of "r" that you are trying to add to "sum" (which should have been "Sum" according to your assignment ear

Re: [R] Loop does not work: Error in else statement (II)

2014-10-02 Thread Frank S.
Jim, Thanks for the comment about else! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www

Re: [R] Loop does not work: Error in else statement (II)

2014-09-30 Thread PIKAL Petr
Hi Slightly better but still html scrambled. see in line > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Frank S. > Sent: Tuesday, September 30, 2014 2:55 PM > To: r-help@r-project.org > Subject: [R] Loop does not work: Erro

Re: [R] Loop does not work: Error in else statement

2014-09-30 Thread Frank S.
Dear Berend and Petr, I do apologise for the disorderly code I posted. I have tried to solve it in a new mail. Frank S. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list htt

Re: [R] Loop does not work: Error in else statement

2014-09-29 Thread PIKAL Petr
Hi > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Frank S. > Sent: Monday, September 29, 2014 9:17 PM > To: r-help@r-project.org > Subject: [R] Loop does not work: Error in else statement > > Hi to all members of R list, > >

Re: [R] Loop does not work: Error in else statement

2014-09-29 Thread Berend Hasselman
Please, please do not post in HTML as the Posting guide requests. See the tail of each message to R-help. Your code is completely messed up and unreadable. Berend On 29-09-2014, at 21:17, Frank S. wrote: > Hi to all members of R list, > > > > I�m working with data.table package, and with 6

Re: [R] Loop Autoregression

2014-06-04 Thread PIKAL Petr
etr > -Original Message- > From: Jonas Ulbrich [mailto:jonas.ulbr...@ruhr-uni-bochum.de] > Sent: Wednesday, June 04, 2014 10:48 AM > To: PIKAL Petr > Subject: Re: [R] Loop Autoregression > > Thanks for the answer. The class of NSS Parameter is data frame. > > On 2014

Re: [R] Loop Autoregression

2014-06-04 Thread PIKAL Petr
more info from your side (at least what object is NSSParameter). Regards Petr > -Original Message- > From: Jonas Ulbrich [mailto:jonas.ulbr...@ruhr-uni-bochum.de] > Sent: Tuesday, June 03, 2014 3:02 PM > To: PIKAL Petr > Subject: RE: [R] Loop Autoregression > > >

Re: [R] Loop Autoregression

2014-06-01 Thread PIKAL Petr
Hi > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Jonas Ulbrich > Sent: Sunday, June 01, 2014 1:51 PM > To: R-help@r-project.org > Subject: [R] Loop Autoregression > > Hello everybody, I have to confess that I am relatively n

Re: [R] Loop Issue

2014-05-23 Thread arun
Hi, You may also try: fun1 <- function(n, repl, val1, val2) {     mat1 <- suppressWarnings(replicate(repl, log(runif(n, val1, val2     mat1[!is.na(mat1)][seq(n)] } #Jim's function fun2 <- function(init, final, val1, val2) {     i <- init     while (i < final) {     u <- runif(1, val1, val2

Re: [R] Loop Issue

2014-05-23 Thread Jim Lemon
On Thu, 22 May 2014 09:11:43 PM Ricardo Rocha wrote: > Hi everybody. > > Consider the following exampling code: > > x=numeric() > for(i in 1:10){ > u=runif(1,-1,2) > x[i]=log(u) > } > This code, in each interation, generates a random value in the (-1,2) > interval and then calculates

Re: [R] Loop Issue

2014-05-22 Thread Yvan Richard
Hi Ricardo Assuming you have a good reason to use such approach (what are you trying to do ultimately?), you can just increment your counter when you get a good value, i.e.: x <- numeric() n <- 0 while (n < 10) { u <- log(runif(1, -1, 2)) if (is.finite(u)) { n <- n+1 x[n] <

Re: [R] Loop to extract from variables in the workspace

2014-04-23 Thread Bea GD
t. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. -Original Message- From: Beatriz R. Gonzalez Dominguez [mailto:aguitatie...@hotmail.com] Sent: 21. april 2014 16:27 To: Frede Aakmann Tøgersen; r-help@r-project.org Subject:

Re: [R] Loop to extract from variables in the workspace

2014-04-21 Thread Frede Aakmann Tøgersen
er. > -Original Message- > From: Beatriz R. Gonzalez Dominguez [mailto:aguitatie...@hotmail.com] > Sent: 21. april 2014 16:27 > To: Frede Aakmann Tøgersen; r-help@r-project.org > Subject: Re: [R] Loop to extract from variables in the workspace > > Hi Frede, > > Many thanks

Re: [R] Loop to extract from variables in the workspace

2014-04-21 Thread Beatriz R. Gonzalez Dominguez
Hi Frede, Many thanks for your reply. 1. The first argument in extract is a Formal class RasterLayer in the Workspace (e.g RR_1981_1 ). 2. I created an intermediate name to hold the result fromthe extract function because I'd like to create several dataframes with the output of the iterative

Re: [R] Loop to extract from variables in the workspace

2014-04-21 Thread Frede Aakmann Tøgersen
Hi Beatriz Did you read the help for extract{raster} carefully? Several things can be wrong. 1) First argument to extract is not a file name but a raster object. 2) In the loop you name an object extract as an intermediate name to hold the result from the extract function. Do you think there co

Re: [R] Loop through columns of outcomes

2013-11-12 Thread Kuma Raj
Very helpful, many thanks. On 12 November 2013 16:09, Rui Barradas wrote: > Hello, > > Once again, use lapply. > > mlist <- lapply(seq_along(m2), function(i) m2[[i]]) > names(mlist) <- paste0("mod", seq_along(mlist)) > > slist <- lapply(mlist, summary) > > > plist <- lapply(slist, `[[`, 'p.table'

Re: [R] Loop through columns of outcomes

2013-11-12 Thread Rui Barradas
Hello, Once again, use lapply. mlist <- lapply(seq_along(m2), function(i) m2[[i]]) names(mlist) <- paste0("mod", seq_along(mlist)) slist <- lapply(mlist, summary) plist <- lapply(slist, `[[`, 'p.table') Hope this helps, Rui Barradas Em 12-11-2013 13:28, Kuma Raj escreveu: Thanks for the s

Re: [R] Loop through columns of outcomes

2013-11-12 Thread Kuma Raj
Thanks for the script which works perfectly. I am interested to do model checking and also interested to extract the coefficients for linear and spline terms. For model checkup I could run this script which will give different plots to test model fit: gam.check(m2[[1]]). Thanks to mnel from SO I co

Re: [R] Loop through columns of outcomes

2013-11-12 Thread Rui Barradas
Hello, Use nested lapply(). Like this: m1 <- lapply(varlist0,function(v) { lapply(outcomes, function(o){ f <- sprintf("%s~ s(time,bs='cr',k=200)+s(temp,bs='cr') + Lag(%s,0:6)", o, v) gam(as.formula(f),family=quasipoisson,na.action=na.omit,data=df) })}) m1 <-

Re: [R] Loop for R

2013-10-23 Thread Jim Lemon
On 10/23/2013 09:51 PM, THIRU MANIAM wrote: Hi, I need kind help from you. I'm doing my assignment in IR and need to do script in R programming and using R studio tool.I don't have any knowledge in R but learning by Youtube. After so long,i successfully came out with below script for precision

  1   2   3   4   5   >