Hi Experts, I am newbie in R. Could you please share your idea to create a stack with no value or zero value? Nrow=1,Ncol=1, Ncell=1, I aim to work with looping, I want to make a first layer with zero values to add other layers further. Thanks. Best Regards, ..................Anup KhanalNorwegian Institute of science and Technology (NTNU)Trondheim, NorwayMob:(+47) 45174313 [[alternative HTML version deleted]]
you can create an empty data frame with yourdata <- data.frame() and then add new records to it with another data table called `newdata` like this.. yourdata <- rbind( yourdata , newdata ) On Mon, Mar 11, 2013 at 9:13 AM, Anup khanal <zanup@hotmail.com> wrote:> > Hi Experts, I am newbie in R. Could you please share your idea to create a > stack with no value or zero value? Nrow=1,Ncol=1, Ncell=1, I aim to work > with looping, I want to make a first layer with zero values to add other > layers further. Thanks. > Best Regards, > ..................Anup KhanalNorwegian Institute of science and Technology > (NTNU)Trondheim, NorwayMob:(+47) 45174313 > > [[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.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hi> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Anup khanal > Sent: Monday, March 11, 2013 2:13 PM > To: r-help at r-project.org > Subject: [R] New Stack > > > Hi Experts, I am newbie in R. Could you please share your idea toIt seems that you have some experience with some programming languages. Before you start with such attempts I would recommend you to print out R intro or maybe R inferno from Patrick Burns and spend let say two or three evenings to read through chapters about data structures and data manipulation. It will spare you much frustration and attempts to twist R to behave like let say C+. You can you can write an R program in C+ style however it will be slow, inefficient and probably quite complicated. Regards Petr> create a stack with no value or zero value? Nrow=1,Ncol=1, Ncell=1, I > aim to work with looping, I want to make a first layer with zero values > to add other layers further. Thanks. > Best Regards, > ..................Anup KhanalNorwegian Institute of science and > Technology (NTNU)Trondheim, NorwayMob:(+47) 45174313 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Don't. This is a classic mistake by newcomers to R that leads to abysmal performance. The best alternative is to compute one column at a time, so your data frame should be initialized with the inputs to your calculations, and you compute output columns as vector expressions of the inputs without looping. For example dta <- data.frame( X=1:10 ) dta$Y <- 2*dta$X+3 dta$clip <- dta$Y > 13 dta$Yc1 <- ifelse( dta$clip, 13, dta$Y ) The ifelse function computes both possible answers for every element of the result and the chooses between them. If you would prefer to do those computations only for selected rows then you can use indexed assignment: dta$Yc2 <- dta$Y dta$Yc2[dta$clip] <- 13 If you absolutely must compute your results in little chunks of rows (e.g. one row at a time) then at least store them into a list as you go and collapse them into one data frame all at once using, say, the sapply function. This avoids allocating a whole sequence of data frames with sizes from 1:n, which is very inefficient use of memory. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Anup khanal <zanup at hotmail.com> wrote:> >Hi Experts, I am newbie in R. Could you please share your idea to >create a stack with no value or zero value? Nrow=1,Ncol=1, Ncell=1, I >aim to work with looping, I want to make a first layer with zero values >to add other layers further. Thanks. >Best Regards, >..................Anup KhanalNorwegian Institute of science and >Technology (NTNU)Trondheim, NorwayMob:(+47) 45174313 > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.