You should be able to use whatever values you are getting from your script right now. I just did the assignment to match what you were showing on the output. The easiest thing to do is to do 'str(X)' from your data and compare it to the 'x' I created -- str(x).
Here is what 'str(x)' gives: > x <- list(40, c(80,160), c(160,80,400)) > str(x) List of 3 $ : num 40 $ : num [1:2] 80 160 $ : num [1:3] 160 80 400 When providing sample data, it is probably best to use 'dput' to it can be reconstructed by the reader: > dput(x) list(40, c(80, 160), c(160, 80, 400)) This gives back what I was using and hopefully it compares with your current output. On Fri, Dec 10, 2010 at 9:00 AM, Amelia Vettori <amelia_vett...@yahoo.co.nz>wrote: > Dear Mr Holtman Sir, > > Thanks a lot for your great solution. This certainly is helping me achieve > what I need to get. However, I shall be hugely thankful to you if you can > guide me in one respect. > > Sir, you have used following commands to assign values to x and y. > > > x <- list(40, c(80,160), c(160,80,400)) > > y <- list(10, c(10,30), c(5,18,20)) > > z <- c(1,2,3) > > But Sir, the problem is these values are basically outputs of some other > process which I am running and chances are these will vary. Sir, it will be > a great help if you can guide me to convert the output (which I am getting) > > > X > [[1]] > [1] 40 > > [[2]] > [1] 80 160 > > [[3]] > [1] 160 80 400 > > to what you have suggested > > x <- list(40, c(80,160), c(160,80,400)) > > So, in that case once I get output in my format, I will convert that output > as provided by you. > > I apologize for taking the liberty of writing to you, but I shall be really > grateful to you, as I have just started getting the feel of 'R' and I know I > need to take lots of efforts to begin with. > > Thanks and eagerly waiting for your guidance. > > Amelia Vettori > > --- On *Fri, 10/12/10, jim holtman <jholt...@gmail.com>* wrote: > > > From: jim holtman <jholt...@gmail.com> > Subject: Re: [R] Adding numbers in Outputs > To: "Amelia Vettori" <amelia_vett...@yahoo.co.nz> > Cc: r-help@r-project.org > Received: Friday, 10 December, 2010, 1:43 PM > > > try this: > > > x <- list(40, c(80,160), c(160,80,400)) > > y <- list(10, c(10,30), c(5,18,20)) > > z <- c(1,2,3) > > mapply(function(a1,a2,a3){ > + a3 * sum(a1 * a2) > + } > + , x > + , y > + , z > + ) > [1] 400 11200 30720 > > > On Fri, Dec 10, 2010 at 5:41 AM, Amelia Vettori > <amelia_vett...@yahoo.co.nz<http://mc/compose?to=amelia_vett...@yahoo.co.nz>> > wrote: > > two OutputsHello! > > > > I am Amelia from Auckland and work for a bank. I am new to R and I have > started my venture with R just a couple of weeks back and this is my first > mail to R-forum. I need following assistance > > > > Suppose my R code generates following outputs as > > > > > >> X > > [[1]] > > [1] 40 > > > > [[2]] > > [1] 80 160 > > > > [[3]] > > [1] 160 80 400 > > > > > >> Y > > > > [[1]] > > > > [1] 10 > > > > > > > > [[2]] > > > > [1] 10 30 > > > > > > > > [[3]] > > > > [1] 5 18 20 > > > > and suppose > > > > Z = c(1, 2, 3) > > > > I need to perform the calculation where I will be multiplying > corresponding terms of X and Y individually and multiplying their sum by Z > and store these results in a dataframe. > > > > I.e. I need to calculate > > > > (40*10) * 1 # (first element of X + First > element of Y) * Z[1] = 400 > > > > ((80*10)+(160*30)) * 2 # 2 row of X and 2nd row of Y = > 11200 > > > > ((160*5)+(80*18)+(400*20)) * 3 # 3rd row of X and 3 row of Y and Z[3] > = 30720 > > > > > > > > So the final output should be > > > > 400 > > 11200 > > 30720 > > > > > > One way of doing it is write R code for individual rows and > > arrive at the result e.g. > > > > ([[X]][1]*[[Y]][1])*1 will result in 400. However, I was just trying to > know some smart way of doing it as there could be number of rows and writing > code for each row will be a cumbersome job. So is there any better way to do > it? > > > > Please guide me. > > > > I thank you in advance. > > > > Thanking > > all > > > > Amelia > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > R-help@r-project.org <http://mc/compose?to=r-h...@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<http://www.r-project.org/posting-guide.html> > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > -- > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > > > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? [[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.