Re: [R] Sequence generation in a table
Vincy, I suppose the following does what you want. yy is now a list which allows for differing lengths of the vectors. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy[[1]] [1] 257 157 57 yy[[2]] [1] 520 420 320 220 120 20 Regards, Jan On 9-12-2010 11:40, Vincy Pyne wrote: c(257, 520, 110) __ 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.
Re: [R] Sequence generation in a table
Dear Sir, Sorry to bother you again. Sir, the R code provided by you gives me following output. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy [[1]] [1] 257 157 57 [[2]] [1] 520 420 320 220 120 20 [[3]] [1] 110 10 The biggest constraint for me is here as an example I have taken only three cases i.e. c(257, 520, 110), however in reality I will be dealing with no of cases and that number is unknown. But your code will certainly generate me the required numbers. In above case for doing further calculations, I can define say yy1 = as.numeric(yy[[1]]) yy2 = as.numeric(yy[2]]) yy3 = as.numeric(yy[[3]]) But when the number of cases are unknown, perhaps this is not the practical way of me defining individually. So is there any way that I can have all the sequence numbers generated can be accommodated in a single dataframe. I sincerely apologize for disturbing you Sir and hope I am able to put up my problem in a proper manner. Regards Vincy Pyne --- On Thu, 12/9/10, Jan van der Laan rh...@eoos.dds.nl wrote: From: Jan van der Laan rh...@eoos.dds.nl Subject: Re: [R] Sequence generation in a table To: r-help@r-project.org, vincy_p...@yahoo.ca Received: Thursday, December 9, 2010, 10:57 AM Vincy, I suppose the following does what you want. yy is now a list which allows for differing lengths of the vectors. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy[[1]] [1] 257 157 57 yy[[2]] [1] 520 420 320 220 120 20 Regards, Jan On 9-12-2010 11:40, Vincy Pyne wrote: c(257, 520, 110) [[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.
Re: [R] Sequence generation in a table
On Thu, Dec 9, 2010 at 12:41 PM, Vincy Pyne vincy_p...@yahoo.ca wrote: The biggest constraint for me is here as an example I have taken only three cases i.e. c(257, 520, 110), however in reality I will be dealing with no of cases and that number is unknown. But your code will certainly generate me the required numbers. In above case for doing further calculations, I can define say yy1 = as.numeric(yy[[1]]) yy2 = as.numeric(yy[2]]) yy3 = as.numeric(yy[[3]]) Why do you want to do that? For example, mean(yy[[1]]) [1] 157 mean(yy1) [1] 157 Liviu __ 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.
Re: [R] Sequence generation in a table
Hi r-help-boun...@r-project.org napsal dne 09.12.2010 12:41:47: Dear Sir, Sorry to bother you again. Sir, the R code provided by you gives me following output. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy [[1]] [1] 257 157 57 [[2]] [1] 520 420 320 220 120 20 [[3]] [1] 110 10 The biggest constraint for me is here as an example I have taken only three cases i.e. c(257, 520, 110), however in reality I will be dealing with no of cases and that number is unknown. But your code will certainly generate me the required numbers. In above case for doing further calculations, I can define say yy1 = as.numeric(yy[[1]]) yy2 = as.numeric(yy[2]]) yy3 = as.numeric(yy[[3]]) Why? Those values are already numeric. lapply(yy, is.numeric) [[1]] [1] TRUE [[2]] [1] TRUE [[3]] [1] TRUE and you can use the same construction to perform almost any operation on list. lapply(yy, max) lapply(yy, mean) lapply(yy, sd) lapply(yy, t.test) Regards Petr But when the number of cases are unknown, perhaps this is not the practical way of me defining individually. So is there any way that I can have all the sequence numbers generated can be accommodated in a single dataframe. I sincerely apologize for disturbing you Sir and hope I am able to put up my problem in a proper manner. Regards Vincy Pyne --- On Thu, 12/9/10, Jan van der Laan rh...@eoos.dds.nl wrote: From: Jan van der Laan rh...@eoos.dds.nl Subject: Re: [R] Sequence generation in a table To: r-help@r-project.org, vincy_p...@yahoo.ca Received: Thursday, December 9, 2010, 10:57 AM Vincy, I suppose the following does what you want. yy is now a list which allows for differing lengths of the vectors. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy[[1]] [1] 257 157 57 yy[[2]] [1] 520 420 320 220 120 20 Regards, Jan On 9-12-2010 11:40, Vincy Pyne wrote: c(257, 520, 110) [[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. __ 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.
Re: [R] Sequence generation in a table
Dear Sirs, I understand these already are numeric values. Sir, Basically I am working on Value at Risk for the Bond portfolio using the historical simulation and for this I need to find out Marked to Market (MTM) value suing the Present Value of the coupon payments for each Bonds (here as an example I have taken only 3). What I have done so far is for a given bond I have found no of days left for maturity. E.g. in 1st case there are 257 days left for maturity. The bond pays coupon twice a year and thus on 257th day the bond will mature and I will be getting the Principal and final coupon payment. Since teh bond is paying the coupons every 6 months, going backward from 257 th day, my earlier coupon payment falls on (257 - 180) = 77 days. (However, in above example, I have just taken 100 just for example purpose) Thus, assuming 100 days, my coupons will be paid on 257, 157, 57days. I need to convert these days in terms of years and so when I try to divide yy defined as yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy/360, I get following error. Error in yy/360 : non-numeric argument to binary operator On the other hand, yy[[1]]/365 fetches me [1] 0.7138889 0.436 0.158 Thus, I am trying to obtain the result yy - lapply(c(257, 520, 110), seq, to=0, by=-100) in such a form, so taht I should be able to further analysis. What I was trying to say is since here I am taking only three bonds, so I can do it individually, however if there are number of bonds (say 1000) in the portfolio, my method of converting the days individually is not practical. I am extremely sorry for the inconvenience caused. I tried to keep my problem short in oder not to consume your valuable time. Regards Vince Pyne --- On Thu, 12/9/10, Petr PIKAL petr.pi...@precheza.cz wrote: From: Petr PIKAL petr.pi...@precheza.cz Subject: Re: [R] Sequence generation in a table To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Thursday, December 9, 2010, 12:03 PM Hi r-help-boun...@r-project.org napsal dne 09.12.2010 12:41:47: Dear Sir, Sorry to bother you again. Sir, the R code provided by you gives me following output. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy [[1]] [1] 257 157 57 [[2]] [1] 520 420 320 220 120 20 [[3]] [1] 110 10 The biggest constraint for me is here as an example I have taken only three cases i.e. c(257, 520, 110), however in reality I will be dealing with no of cases and that number is unknown. But your code will certainly generate me the required numbers. In above case for doing further calculations, I can define say yy1 = as.numeric(yy[[1]]) yy2 = as.numeric(yy[2]]) yy3 = as.numeric(yy[[3]]) Why? Those values are already numeric. lapply(yy, is.numeric) [[1]] [1] TRUE [[2]] [1] TRUE [[3]] [1] TRUE and you can use the same construction to perform almost any operation on list. lapply(yy, max) lapply(yy, mean) lapply(yy, sd) lapply(yy, t.test) Regards Petr But when the number of cases are unknown, perhaps this is not the practical way of me defining individually. So is there any way that I can have all the sequence numbers generated can be accommodated in a single dataframe. I sincerely apologize for disturbing you Sir and hope I am able to put up my problem in a proper manner. Regards Vincy Pyne --- On Thu, 12/9/10, Jan van der Laan rh...@eoos.dds.nl wrote: From: Jan van der Laan rh...@eoos.dds.nl Subject: Re: [R] Sequence generation in a table To: r-help@r-project.org, vincy_p...@yahoo.ca Received: Thursday, December 9, 2010, 10:57 AM Vincy, I suppose the following does what you want. yy is now a list which allows for differing lengths of the vectors. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy[[1]] [1] 257 157 57 yy[[2]] [1] 520 420 320 220 120 20 Regards, Jan On 9-12-2010 11:40, Vincy Pyne wrote: c(257, 520, 110) [[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]] __ 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.
Re: [R] Sequence generation in a table
On Thu, Dec 9, 2010 at 1:24 PM, Vincy Pyne vincy_p...@yahoo.ca wrote: yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy/360, I get following error. Error in yy/360 : non-numeric argument to binary operator On the other hand, yy[[1]]/365 fetches me [1] 0.7138889 0.436 0.158 What about this? bond.fun - function(x, days=360) {x/days} lapply(yy, bond.fun) [[1]] [1] 0.7138889 0.436 0.158 [[2]] [1] 1. 1.1667 0.8889 0.6111 0. 0.0556 [[3]] [1] 0.3056 0.0278 lapply(yy, bond.fun, days=366) [[1]] [1] 0.7021858 0.4289617 0.1557377 [[2]] [1] 1.42076503 1.14754098 0.87431694 0.60109290 0.32786885 0.05464481 [[3]] [1] 0.30054645 0.02732240 __ 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.
Re: [R] Sequence generation in a table
Try this: sapply(sapply(c(257, 520, 110), seq, by = -100), '/', 360) On Thu, Dec 9, 2010 at 10:24 AM, Vincy Pyne vincy_p...@yahoo.ca wrote: Dear Sirs, I understand these already are numeric values. Sir, Basically I am working on Value at Risk for the Bond portfolio using the historical simulation and for this I need to find out Marked to Market (MTM) value suing the Present Value of the coupon payments for each Bonds (here as an example I have taken only 3). What I have done so far is for a given bond I have found no of days left for maturity. E.g. in 1st case there are 257 days left for maturity. The bond pays coupon twice a year and thus on 257th day the bond will mature and I will be getting the Principal and final coupon payment. Since teh bond is paying the coupons every 6 months, going backward from 257 th day, my earlier coupon payment falls on (257 - 180) = 77 days. (However, in above example, I have just taken 100 just for example purpose) Thus, assuming 100 days, my coupons will be paid on 257, 157, 57days. I need to convert these days in terms of years and so when I try to divide yy defined as yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy/360, I get following error. Error in yy/360 : non-numeric argument to binary operator On the other hand, yy[[1]]/365 fetches me [1] 0.7138889 0.436 0.158 Thus, I am trying to obtain the result yy - lapply(c(257, 520, 110), seq, to=0, by=-100) in such a form, so taht I should be able to further analysis. What I was trying to say is since here I am taking only three bonds, so I can do it individually, however if there are number of bonds (say 1000) in the portfolio, my method of converting the days individually is not practical. I am extremely sorry for the inconvenience caused. I tried to keep my problem short in oder not to consume your valuable time. Regards Vince Pyne --- On Thu, 12/9/10, Petr PIKAL petr.pi...@precheza.cz wrote: From: Petr PIKAL petr.pi...@precheza.cz Subject: Re: [R] Sequence generation in a table To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Thursday, December 9, 2010, 12:03 PM Hi r-help-boun...@r-project.org napsal dne 09.12.2010 12:41:47: Dear Sir, Sorry to bother you again. Sir, the R code provided by you gives me following output. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy [[1]] [1] 257 157 57 [[2]] [1] 520 420 320 220 120 20 [[3]] [1] 110 10 The biggest constraint for me is here as an example I have taken only three cases i.e. c(257, 520, 110), however in reality I will be dealing with no of cases and that number is unknown. But your code will certainly generate me the required numbers. In above case for doing further calculations, I can define say yy1 = as.numeric(yy[[1]]) yy2 = as.numeric(yy[2]]) yy3 = as.numeric(yy[[3]]) Why? Those values are already numeric. lapply(yy, is.numeric) [[1]] [1] TRUE [[2]] [1] TRUE [[3]] [1] TRUE and you can use the same construction to perform almost any operation on list. lapply(yy, max) lapply(yy, mean) lapply(yy, sd) lapply(yy, t.test) Regards Petr But when the number of cases are unknown, perhaps this is not the practical way of me defining individually. So is there any way that I can have all the sequence numbers generated can be accommodated in a single dataframe. I sincerely apologize for disturbing you Sir and hope I am able to put up my problem in a proper manner. Regards Vincy Pyne --- On Thu, 12/9/10, Jan van der Laan rh...@eoos.dds.nl wrote: From: Jan van der Laan rh...@eoos.dds.nl Subject: Re: [R] Sequence generation in a table To: r-help@r-project.org, vincy_p...@yahoo.ca Received: Thursday, December 9, 2010, 10:57 AM Vincy, I suppose the following does what you want. yy is now a list which allows for differing lengths of the vectors. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy[[1]] [1] 257 157 57 yy[[2]] [1] 520 420 320 220 120 20 Regards, Jan On 9-12-2010 11:40, Vincy Pyne wrote: c(257, 520, 110) [[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]] __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted
Re: [R] Sequence generation in a table
Hi r-help-boun...@r-project.org napsal dne 09.12.2010 13:24:17: Dear Sirs, I understand these already are numeric values. Sir, Basically I am working on Value at Risk for the Bond portfolio using the historical simulation and for this I need to find out Marked to Market (MTM) value suing the Present Value of the coupon payments for each Bonds (here as an example I have taken only 3). What I have done so far is for a given bond I have found no of days left for maturity. E.g. in 1st case there are 257 days left for maturity. The bond pays coupon twice a year and thus on 257th day the bond will mature and I will be getting the Principal and final coupon payment. Since teh bond is paying the coupons every 6 months, going backward from 257 th day, my earlier coupon payment falls on (257 - 180) = 77 days. (However, in above example, I have just taken 100 just for example purpose) Thus, assuming 100 days, my coupons will be paid on 257, 157, 57days. I need to convert these days in terms of years and so when I try to divide yy defined as yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy/360, I get following error. Error in yy/360 : non-numeric argument to binary operator Did you bother to read ?lapply or some intro documentation? On the other hand, yy[[1]]/365 fetches me [1] 0.7138889 0.436 0.158 I do not believe it. I got yy[[1]]/365 [1] 0.7041096 0.4301370 0.1561644 and as I already told you you can use lapply for almost any kind of computation. Just try lapply(yy, /, 365) [[1]] [1] 0.7041096 0.4301370 0.1561644 [[2]] [1] 1.42465753 1.15068493 0.87671233 0.60273973 0.32876712 0.05479452 [[3]] [1] 0.30136986 0.02739726 Regards Petr Thus, I am trying to obtain the result yy - lapply(c(257, 520, 110), seq, to=0, by=-100) in such a form, so taht I should be able to further analysis. What I was trying to say is since here I am taking only three bonds, so I can do it individually, however if there are number of bonds (say 1000) in the portfolio, my method of converting the days individually is not practical. I am extremely sorry for the inconvenience caused. I tried to keep my problem short in oder not to consume your valuable time. Regards Vince Pyne --- On Thu, 12/9/10, Petr PIKAL petr.pi...@precheza.cz wrote: From: Petr PIKAL petr.pi...@precheza.cz Subject: Re: [R] Sequence generation in a table To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Thursday, December 9, 2010, 12:03 PM Hi r-help-boun...@r-project.org napsal dne 09.12.2010 12:41:47: Dear Sir, Sorry to bother you again. Sir, the R code provided by you gives me following output. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy [[1]] [1] 257 157 57 [[2]] [1] 520 420 320 220 120 20 [[3]] [1] 110 10 The biggest constraint for me is here as an example I have taken only three cases i.e. c(257, 520, 110), however in reality I will be dealing with no of cases and that number is unknown. But your code will certainly generate me the required numbers. In above case for doing further calculations, I can define say yy1 = as.numeric(yy[[1]]) yy2 = as.numeric(yy[2]]) yy3 = as.numeric(yy[[3]]) Why? Those values are already numeric. lapply(yy, is.numeric) [[1]] [1] TRUE [[2]] [1] TRUE [[3]] [1] TRUE and you can use the same construction to perform almost any operation on list. lapply(yy, max) lapply(yy, mean) lapply(yy, sd) lapply(yy, t.test) Regards Petr But when the number of cases are unknown, perhaps this is not the practical way of me defining individually. So is there any way that I can have all the sequence numbers generated can be accommodated in a single dataframe. I sincerely apologize for disturbing you Sir and hope I am able to put up my problem in a proper manner. Regards Vincy Pyne --- On Thu, 12/9/10, Jan van der Laan rh...@eoos.dds.nl wrote: From: Jan van der Laan rh...@eoos.dds.nl Subject: Re: [R] Sequence generation in a table To: r-help@r-project.org, vincy_p...@yahoo.ca Received: Thursday, December 9, 2010, 10:57 AM Vincy, I suppose the following does what you want. yy is now a list which allows for differing lengths of the vectors. yy - lapply(c(257, 520, 110), seq, to=0, by=-100) yy[[1]] [1] 257 157 57 yy[[2]] [1] 520 420 320 220 120 20 Regards, Jan On 9-12-2010 11:40, Vincy Pyne wrote: c(257, 520, 110) [[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