similar to: for loop; lm() regressions; list of vectors

Displaying 20 results from an estimated 30000 matches similar to: "for loop; lm() regressions; list of vectors"

2010 Mar 31
1
for loop; lm() regressions; list of vectors - lapply - accolades and square brackets??
Hello and thank you both for your answers! Dennis, I tried to simply run lm(a ~ b) after re-importing "a" as a matrix, but I get the following error message: Error in model.frame.default(formula = a ~ b, drop.unused.levels = TRUE) : invalid type (list) for variable 'a' so maybe I have to specify something in the arguments? What do you think? David, I tried your syntax as
2012 Jun 18
2
Need to append vector to all levels of nested list WITHOUT a loop
Hi everyone, I have a list betaMoments with 2 levels, e.g. > beta1 = list( + m = 4, + v = 5 + ) > beta2 = list( + m = 6, + v = 7 + ) > > betaMoments = list() > betaMoments[[1]] = beta1 > betaMoments[[2]] = beta2 and I have a matrix Names which has the same number of lines as the list has first level elements (here 2; beta1 and beta2). Now I need to make
2015 Apr 12
2
Loop sobre muchos data frames
Jorge, estimados colaboradores de R-help Estuve tratando de utilizar un script para uno de los pasos en mi análisis, que es transformar cada uno de los corpus en mi espacio de trabajo en un objeto TermDocumentMatrix Tengo un vector llamado bNames que lista todos los corpus que quiero pasar a TDM, y construí los siguientes comandos: tdm.n1 <- vector('list', length = length(bNames))
2007 Jun 19
4
How do I avoid a loop?
Hi, I start with an array of booleans: x <- c( TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE ); I want to define an y <- f(x) such that: y <- c( 1, 2, 3, 0, 0, 1, 2, 0, 1 ); In other words, do a cumsum when I see a TRUE, but reset to 0 if I see a FALSE. I know I can do this with a very slow and ugly loop or maybe use apply, but I was hoping there are some R experts out
2012 Oct 25
3
problem in finding sizes of objects using a for loop
Dear All, I wanted to extract the sizes of all created objects. For E.g when I created 2 objects(x and y), I got their sizes using the following code: > x<-rnorm(10000) > y<-runif(100,min=40,max=1000) > ls() [1] "x" "y" > object.size(x) 80024 bytes > object.size(y) 824 bytes However, I was unable to get their sizes when I used a for loop in the following
2013 Oct 17
1
Reshape
Hello, I have data frame like the one created below, ##input data Person <- c(1,1,1,1,1,1,2,2) Amount <- c(100,10,100,10,100,10,50,150) Date <- c("12/01/2012", "12/01/2012", "01/01/2013","01/01/2013","02/01/2013","02/01/2013","12/01/2012","12/01/2012") df <- data.frame(Person,Amount,Date) I would
2013 Feb 17
2
Loop
Hi all, I want to execute a loop of a program: for (u in Timeframemin:Timeframe){} Imagine that Timeframemin<-10 Timefram<-10000 Is it posible to execute the loop but only proving from 10 to 10000 but jumping 10 each time, for example, execute for 10,20,30.....to Timeframe. Other question is, when a program is "heavy" and has a lot of loops to execute (how can I know where
2012 Jan 01
3
rep() inside of lm()?
HI all, I'm new to R. Say I have a multi-layered list called newlist. ############ > str(newlist) List of 2 $ :List of 5 ..$ : num [1:8088] NA 464 482 535 557 ... ..$ : num [1:8088, 1:2] NA 464 482 535 557 ... ..$ : num [1:8088, 1:3] NA 464 482 535 557 ... ..$ : num [1:8088, 1:4] NA 464 482 535 557 ... ..$ : num [1:8088, 1:5] NA 464 482 535 557 ... $ :List of 3 ..$ : num
2013 Mar 28
2
how to search a list that contains multiple dissimilar vectors?
Dear All, This is a simple question, but I'm stumped about the simplest way to search a list object such as the following: This randomish snippet: n <- c(round(runif(round(runif(1,1,10),0),1,10),0)) alist <- new("list") for (i in seq_along(n)) { alist[[i]] <- c(round(runif(round(runif(1,1,10),0),1,10),0)) } names(alist) <- sample(letters[1:length(n)]) rm(n);c(alist)
2009 Oct 27
1
New vector based on if/else statement within for loop?
Hello, I am trying to create a new vector (w) that is based on comparing two vectors (P and Z). The compaison is simple (I created a for loop that reassigns w based on if statement), all Z values >= 24 and P values <=1, w=88 else w=77. I am not getting the correct results for w, see example code below. Any thoughts or suggestions on the correct method. Thank you, Doug P <-
2017 Nov 14
1
Dates to numeric in for loop
Hi Can anyone explain why a date becomes numeric when you loop over a series of dates? > dt <- Sys.Date() > dt [1] "2017-11-14" > class(dt) [1] "Date" > dts <- dt - 1:0 > class(dts) [1] "Date" > > for (i in dts) { + print(i) + print(class(i)) + print(as.Date(i, "1970-01-01")) + print(class(as.Date(i,
2010 May 04
1
Avoiding for-loop for splitting vector into subvectors based on positions
Dear all, I'm trying to optimize code and want to avoid for-loops as much as possible. I'm applying a calculation on subvectors from a big one, and I get the subvectors by using a vector of starting positions: x <- 1:10 pos <- c(1,4,7) n <- length(x) I try to do something like this : pos2 <- c(pos, n+1) out <- c() for(i in 1:n){ tmp <- x[pos2[i]:pos2[i+1]]
2011 Feb 02
2
Counter in a For Loop - Efficiency Issue
I have a 32000 x 14 matrix (M) where entry (x, y) corresponds to person x at a discrete time y. I then have a matrix (M2) of 60000 x 2 where each entry is a an event by a person that is in the above 32000 and at a time that is in the range of the discrete time points above. I want to populate the another matrix (M3) such that (x, y) is the number of events of person x between times y-1 and y. This
2015 Apr 10
5
Loop sobre muchos data frames
Jorge Gracias por el consejo. Aparentemente no lo estoy aplicando bien, pues el objeto que obtengo no contiene lo que quiero. Me explico, al ejecutar txt <- vector('list', length = length(names)) #names el el vector donde ya tenía almacenada la lista de txt's for(i in seq_along(txt)){ txt[[i]] <- Corpus(VectorSource(names[i])) } obtengo el objeto txt: > class(txt) [1]
2008 Dec 12
3
loop with dates
Hello, I am trying to do a loop with dates, but when I try to use the index is not a date. Fcorte <- as.Date('2008/11/30',format = "%Y/%m/%d") fini <- Fcorte + 1 ffin <- seq(fini,by='months',length=2)[2] - 1 for (i in seq(fini,to = ffin, by='days')) print (weekdays(i)) # i doesn't a date How can I do a loop with dates and get the
2012 Jan 31
1
R help, labeling the tick marks as I want
R help, I would like to change the labels of my tick marks on the x-axis, and I am having difficulty understanding how. Basically, my current axis labels are: 0, 50, 100, 150, 200, and I would like: 1962Q1, 1974Q2, 186Q4, 1999Q2, 2011Q4. With all respect to generality, could you please simply tell me the code to achieve this in the context of this problem? I learn programming by example and
2004 Feb 09
1
Subset function of lm(); "rolling regressions"
Folks, I asked a question on this mailing list about the subset support of lm(). In a flash, I got three helpful responses from Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net> Erin Hodgess <hodgess at gator.uhd.edu> and Peter Dalgaard <p.dalgaard at biostat.ku.dk> :-) and it was just great. The mistake I was making was in not understanding the notion of a
2011 Dec 26
4
Other ways to lm() regression? (non-loop?)
Hi, I'm quite new to R (1 month full time use so far). I have to run loop regressions VERY often in my work, so I would appreciate some new methodology that I'm not considering. #--------------------------------------------------------------------------------------------- y<-matrix(rnorm(100),ncol=10,nrow=10) x<-matrix(rnorm(50),ncol=5,nrow=10) #Suppose I want to run the
2013 Feb 07
4
help with creating new variables using a loop
Hi there, I've got a set of 10 numeric variables called Mood1 to Mood10 in a dataset called mood. I'm trying to create a set of 10 new variables called m1 to m10 so that m1=Mood1*1, m2=Mood2*2, etc to m10=Mood10*10 Trawling through the internet, I eventually tried the following code: for (i in 1:10){ assign(x=paste0("mood$m",i),
2015 Apr 10
3
Loop sobre muchos data frames
Hola a todos! Estoy en un proyecto de text mining y por razones de los recursos con que cuento tuve que separar los archivos de texto de input del proyecto en muchos archivos pequeños. Luego de transformar cada uno de estos archivos en un corpus separado, puedo aplicar limpieza sobre cada corpus, buscar n-gramas, construir cada termDocumentMatrix y finalmente reunir todo en una sola TDM. Pero