[R] Change in order of names after applying plyr package

2012-09-26 Thread Vincy Pyne
Dear R helpers I have following two data.frames viz. equity_data and param. equity_data = data.frame(security_id = c(Air, Air, Air, Air, Air, Air, Air, Air, Air, Air, Air, Air, AB, AB, AB, AB, AB, AB, AB, AB, AB, AB, AB, AB, AD,  AD, AD, AD, AD, AD, AD, AD, AD, AD, AD, AD), ason_date =

[R] How to append the random no.s for different variables in the same data.frame

2012-09-12 Thread Vincy Pyne
Dear R helpers, (At the outset I sincerely apologize if I have not put forward my following query properly, though I have tried to do so.) Following is a curtailed part of my R - code where I am trying to generate say 100 random no.s for each of the products under consideration.

Re: [R] How to append the random no.s for different variables in the same data.frame

2012-09-12 Thread Vincy Pyne
Dear Mr Weylandt and R helpers, Thanks a lot for your suggestion. Unfortunately the return statement in my original R code returns me different results which are obtained after processing the function I have constructed. My requirement for storing the product-wise random numbers is just a

[R] Maintaining Column names while writing csv file.

2012-07-19 Thread Vincy Pyne
Dear R helpers, I have one trivial problem while writing an output file in csv format. I have two dataframes say df1 and df2 which I am reading from two different csv files. df1 has column names as date, r1, r2, r3 while the dataframe df2 has column names as date, 1w, 2w. (the dates in

[R] How to have original (name) order after melt and cast command

2012-07-18 Thread Vincy Pyne
Dear R helpers, I have a data.frame as given below - dat1 = data.frame(date = as.Date(c(3/30/12,3/29/12,3/28/12,3/27/12,3/26/12, 3/23/12,3/22/12,3/21/12,3/20/12, 3/30/12,3/29/12,3/28/12,3/27/12, 3/26/12,3/23/12,3/22/12,3/21/12,3/20/12, 3/30/12,3/29/12,3/28/12,

Re: [R] How to have original (name) order after melt and cast command

2012-07-18 Thread Vincy Pyne
original (name) order after melt and cast command To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Wednesday, July 18, 2012, 11:18 AM Hello, Try the following. # This is your code df_sorted = df[order(as.Date(df$date, %m/%d/%Y), decreasing = TRUE),] # This is my code nams

Re: [R] How to use Sys.time() while writing a csv file name

2012-07-04 Thread Vincy Pyne
file name To: Vincy Pyne vincy_p...@yahoo.ca, r-help@r-project.org Received: Wednesday, July 4, 2012, 5:38 AM You forgot to follow the posting guide and tell us what operating system you are using (sessionInfo), but I am going to guess that you are on Windows where the colon (:) is an illegal symbol

[R] How to use Sys.time() while writing a csv file name

2012-07-03 Thread Vincy Pyne
Dear R helpers, I am using Beta distribution to generate the random no.s (recovery rates in my example). However, each time I need to save these random no.s in a csv format. To distinguish different csv files, one way I thought was use of Sys.time in the file name. My code is as follows - #

[R] What's wrong with MEAN?

2012-05-22 Thread Vincy Pyne
Dear R helpers, I have recently installed R version 2.15.0 I just wanted to calculate mean(16, 18) Surprisingly I got answer as mean(16, 18) [1] 16 mean(18, 16) [1] 18 mean(14, 11, 17, 9, 5, 18) [1] 14 So instead of calculating simple Arithmetic average, mean command is generating

Re: [R] What's wrong with MEAN?

2012-05-22 Thread Vincy Pyne
Subject: RE: [R] What's wrong with MEAN? To: Vincy Pyne vincy_p...@yahoo.ca, r-help@r-project.org r-help@r-project.org Received: Tuesday, May 22, 2012, 9:17 AM You'll need to pass the data as a vector. mean(16, 18) is asking the mean of 16. 18 is passed to the second argument which is trim. So

[R] Multiple Conditional Statement

2012-04-24 Thread Vincy Pyne
Dear R helpers, I have two separate data frames. In one data frame the transaction data is stored and the other data frame has exchange rates stored say rate_A and rate_B where rate_A and rate_B are series of rates. rate_A and rate_B are properly defined and I am reading them through the

[R] Matrix multiplication by multple constants

2012-04-20 Thread Vincy Pyne
Dear R helpers Suppose x  - c(1:3) y  - matrix(1:12, ncol = 3, nrow = 4) y [,1] [,2] [,3] [1,]    1    5    9 [2,]    2    6   10 [3,]    3    7   11 [4,]    4    8   12 I wish to multiply 1st column of y by first element of x i.e. 1, 2nd column of y by 2nd element of x i.e. 2 an so

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Vincy Pyne
multiplication by multple constants To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Friday, April 20, 2012, 8:57 AM try this: x  - 1:3 y  - matrix(1:12, ncol = 3, nrow = 4) y * rep(x, each = nrow(y)) I hope it helps. Best, Dimitris On 4/20/2012 10:51 AM, Vincy Pyne

[R] Constructing a data.frame from csv files

2012-01-11 Thread Vincy Pyne
Dear R helpers, Following is my R code where I am trying to calculate returns and then trying to create a data.frame. Since, I am not aware how many instruments I will be dealing so I have constructed a function. My R code is as follows - library(plyr) mydata - data.frame(instru_name =

Re: [R] Constructing a data.frame from csv files

2012-01-11 Thread Vincy Pyne
the required data.frame. Thanks again. With warm regards Vincy --- On Wed, 1/11/12, jim holtman jholt...@gmail.com wrote: From: jim holtman jholt...@gmail.com Subject: Re: [R] Constructing a data.frame from csv files To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Wednesday, January

[R] KS and AD test for Generalized PAreto and Generalized Extreme value

2012-01-04 Thread Vincy Pyne
Dear R helpers, I need to use KS and AD test for Generalized Pareto and Generalized extreme value. E.g. if I need to use KS for Weibull, I have teh syntax ks.test(x.wei,pweibull, shape=2,scale=1) Similarly, for AD I use ad.test(x, distr.fun, ...) My problem is fir given data, I have

[R] Matching two datasets and updating values

2011-10-04 Thread Vincy Pyne
Dear R forum I have two datafarmes with category and cat_val forming one dataframe and cust and cust_category forming another dataframe. category = c(C, D, B, A) cat_val = c(0.10, 0.25, 0.40, 0.54) cust = c(cust_1, cust_2, cust_3, cust_4, cust_5, cust_6, cust_7, cust_8, cust_9, cust_10)

[R] Question regarding dnorm()

2011-09-14 Thread Vincy Pyne
Hi, I have one basic doubt. Suppose X ~ N(50,10). I need to calculate Probability X = 50. dnorm(50, 50, 10) gives me [1] 0.03989423 My understanding is (which is bit statistical or may be mathematical) on a continuous scale, Probability of the type P(X = .) are nothing but 1/Infinity

Re: [R] Question regarding dnorm()

2011-09-14 Thread Vincy Pyne
Ellison and Mr Mark for your guidance. Regards Vincy --- On Wed, 9/14/11, S Ellison s.elli...@lgcgroup.com wrote: From: S Ellison s.elli...@lgcgroup.com Subject: RE: [R] Question regarding dnorm() To: Vincy Pyne vincy_p...@yahoo.ca, r-help@r-project.org r-help@r-project.org Received: Wednesday

[R] Autocorrelation using acf

2011-08-25 Thread Vincy Pyne
wrote: From: Prof Brian Ripley rip...@stats.ox.ac.uk Subject: Re: [R] Autocorrelation using library(tseries) To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Wednesday, August 24, 2011, 9:08 AM Your understanding is wrong.  For a start, there is no function acf

[R] Autocorrelation using library(tseries)

2011-08-24 Thread Vincy Pyne
Dear R list I am trying to understand the auto-correlation concept. Auto-correlation is the self-correlation of random variable X with a certain time lag of say t. The article http://www.mit.tut.fi/MIT-3010/luentokalvot/lk10-11/MDA_lecture16_11.pdf; (Page no. 9 and 10) gives the methodology

[R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
Dear R list, I have one very elementary question regrading correlation between two variables. x = c(44,46,46,47,45,43,45,44) y = c(44,43,41,41,46,48,44,43) cov(x, y) [1] -2.428571 However, if I try to calculate the covariance using the formula as covariance = sum((x-mean(x))*(y-mean(y)))/8

Re: [R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
ted.hard...@wlandres.net Subject: Re: [R] Correlation discrepancy To: r-help@r-project.org Cc: Vincy Pyne vincy_p...@yahoo.ca Received: Tuesday, August 23, 2011, 11:38 AM In addition, something has gone wrong, Vincy, with your data x,y between evaluating cov(x,y) and evaluating your explicit

Re: [R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
: Re: [R] Correlation discrepancy To: r-help@r-project.org Cc: Vincy Pyne vincy_p...@yahoo.ca Received: Tuesday, August 23, 2011, 11:38 AM In addition, something has gone wrong, Vincy, with your data x,y between evaluating cov(x,y) and evaluating your explicit formula. If I repeat your commands

[R] Meaning of %%

2011-07-13 Thread Vincy Pyne
Dear r helpers This may be very elementary question but I couldn't figure out what does the operator %% do? E.g. p - 100 q - 200 p%%q [1] 100 q%%p [1] 0 Please guide. Vincy [[alternative HTML version deleted]] __ R-help@r-project.org

Re: [R] Meaning of %%

2011-07-13 Thread Vincy Pyne
, Thierry thierry.onkel...@inbo.be Subject: RE: [R] Meaning of %% To: Vincy Pyne vincy_p...@yahoo.ca, r-help@r-project.org r-help@r-project.org Received: Wednesday, July 13, 2011, 10:13 AM help(%%) ir. Thierry Onkelinx

[R] Generalized Logistic and Richards Curve

2011-07-07 Thread Vincy Pyne
Dear R helpers, I am not a statistician and right now struggling with Richards curve. Wikipedia says (http://en.wikipedia.org/wiki/Generalised_logistic_function) The generalized logistic curve or function, also known as Richard's curve is a widely-used and flexible sigmoid function for growth

[R] Value of 'pi'

2011-05-30 Thread Vincy Pyne
Dear R helpers, I have one basic doubt about the value of pi. In school, we have learned that pi = 22/7 (which is = 3.142857). However, if I type pi in R, I get pi = 3.141593. So which value of pi should be considered? Regards Vincy [[alternative HTML version deleted]]

Re: [R] Value of 'pi'

2011-05-30 Thread Vincy Pyne
That's the beauty of this R forum. This forum is full of knowledgeable wizards and replies received along-with the related discussions pertaining to a simple harmless question like this enriches us tremendously. Thanks a lot for all your comments. I am sticking to the value of 'pi' as provided

[R] R forum for only Statistics

2011-04-28 Thread Vincy Pyne
Hi! I wish to know if there is any R forum which is meant only for Statistics? I mean where we can clarify our statistics doubts and seek knowledge. I know there are lot many books and internet sites, but 'R forum' has altogether different standard and very high level and one can learn a lot

[R] Reversing order of vector

2011-03-29 Thread Vincy Pyne
Dear R helpers Suppose I have a vector as vect1 = as.character(c(ABC, XYZ, LMN, DEF)) vect1 [1] ABC XYZ LMN DEF I want to reverse the order of this vector as vect2 = c(DEF, LMN, XYZ, ABC) Kindly guide Regards Vincy [[alternative HTML version deleted]]

[R] Ordering data.frame based on class

2011-03-28 Thread Vincy Pyne
Dear R helpers Suppose I have a data.frame as given below - my_dat = data.frame(class = c(XYZ, XYZ, XYZ, XYZ, XYZ,ABC, ABC, ABC, ABC, ABC ),  var1 = c(20, 14, 89, 81, 17, 44, 36, 41, 11, 36), var2 = c(1001, 250, 456, 740, 380, 641, 111, 209, 830, 920)) my_dat    class var1 var2 1    XYZ   20

[R] Resending the mail - Ordering data.frame based on some class

2011-03-28 Thread Vincy Pyne
Dear R helpers I am resending my mail as the output I desire was not properly visible and I apologize for the same. Suppose I have a data.frame as given below - my_dat = data.frame(class = c(XYZ, XYZ, XYZ, XYZ, XYZ,ABC, ABC, ABC, ABC, ABC ),  var1 = c(20, 14, 89, 81, 17, 44, 36, 41, 11, 36),

Re: [R] Ordering data.frame based on class

2011-03-28 Thread Vincy Pyne
Dear sir, Thanks for the great solution. Regards Vincy --- On Mon, 3/28/11, Henrique Dallazuanna www...@gmail.com wrote: From: Henrique Dallazuanna www...@gmail.com Subject: Re: [R] Ordering data.frame based on class To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Monday

[R] Appending data to a data.frame and writing a csv

2011-03-25 Thread Vincy Pyne
Dear R helpers exposure - data.frame(id = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20), ead = c(9483.686,5,6843.4968,10509.37125,21297.8905,5,706152.8354, 62670.5625, 687.801995,50641.4875,59227.125,43818.5778,52887.72534,601788.7937,

Re: [R] Appending data to a data.frame and writing a csv

2011-03-25 Thread Vincy Pyne
and writing a csv To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Friday, March 25, 2011, 4:02 PM Hi Vincy, Please read the help file, particularly the part about write.csv and write.csv2 where it says These wrappers are deliberately inflexible: they are designed to ensure

[R] Correlation for no of variables

2011-03-21 Thread Vincy Pyne
Dear R helpers, Suppose I have stock returns data of say 1500 companies each for say last 4 years. Thus I have a matrix of dimension say 1000 * 1500 i.e. 1500 columns representing companies and 1000 rows of their returns. I need to find the correlation matrix of these 1500 companies. So I

Re: [R] Correlation for no of variables

2011-03-21 Thread Vincy Pyne
will refer to the packages you have suggested. Thanks again Vincy --- On Mon, 3/21/11, Peter Langfelder peter.langfel...@gmail.com wrote: From: Peter Langfelder peter.langfel...@gmail.com Subject: Re: [R] Correlation for no of variables To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org

[R] One to One Matching multiple vectors

2011-03-16 Thread Vincy Pyne
Dear R helpers Suppose, x = c(0,  1,  2,  3) y = c(A, B, C, D) z = c(1, 3) For given values of z, I need to the values of y. So I should get B and D. I tried doing y[x][z] but it gives y[x][z] [1] A C Kindly guide. Regards Vincy [[alternative HTML version deleted]]

[R] Matching two vectors

2011-03-15 Thread Vincy Pyne
Dear R helpers Suppose I have a vector as vect_1 = c(AAA, AA, A, BBB, BB, B, CCC) vect_1_id = c(1:length(vect_1)) Through some process I obtain vect_2_id = c(2, 3, 7), then I need a new vector say vect_2 which will give me vect2 = (AA, A, CCC)  i.e. I need the subset of vect_1 as per

[R] Identifying unique pairs

2011-03-12 Thread Vincy Pyne
Dear R helpers Suppose I have a data frame as given below mydat = data.frame(x = c(1,1,1, 2, 2, 2, 2, 2, 5, 5, 6), y = c(10, 10, 10, 8, 8, 8, 7, 7, 2, 2, 4)) mydat     x y 1  1 10 2  1 10 3  1 10 4  2   8 5  2   8 6  2   8 7  2  

Re: [R] Identifying unique pairs

2011-03-12 Thread Vincy Pyne
Thanks sir for your reply. Unfortunately I couldn't figure out the solution. Vincy --- On Sat, 3/12/11, Dennis Murphy djmu...@gmail.com wrote: From: Dennis Murphy djmu...@gmail.com Subject: Re: [R] Identifying unique pairs To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received

Re: [R] Identifying unique pairs

2011-03-12 Thread Vincy Pyne
.ff.cuni.cz wrote: From: Petr Savicky savi...@praha1.ff.cuni.cz Subject: Re: [R] Identifying unique pairs To: r-help@r-project.org Received: Saturday, March 12, 2011, 2:10 PM On Sat, Mar 12, 2011 at 03:20:01AM -0800, Vincy Pyne wrote: Dear R helpers Suppose I have a data frame as given below

[R] Generation of random numbers in a function - (Return command)

2011-03-11 Thread Vincy Pyne
Dear R helpers I have following data.frame and for each product_name, I have associated mean and standard deviation. I need to generate 1000 random no.s for each of these products and find the respective mean and standard deviation.   My R code is as follows.   library(plyr) library(reshape2)

[R] How to use conditional statement

2011-03-10 Thread Vincy Pyne
Dear R helpers Suppose val1 = c(10, 20, 35, 80, 12) val2 = c(3, 8, 11, 7) I want to select either val1 or val2 depending on value of third quantity val3. val3 assumes either of the values Monthly or Yearly. If val3 = Monthly, then val = val1 and if val3 = Yearly, then val = val2. I tried the

Re: [R] How to use conditional statement

2011-03-10 Thread Vincy Pyne
complex I'd prefer the latter. Duncan Murdoch Single = is for setting arguments within a function call. If you want to test equality, then double == is required. See ?== HTH, Ivan Le 3/10/2011 11:45, Vincy Pyne a écrit : Dear R helpers Suppose val1 = c(10, 20, 35, 80, 12) val2 = c

[R] Rearranging the data

2011-03-09 Thread Vincy Pyne
Dear R helpers, xx = data.frame(country = c(USA, UK, Canada), x = c(10, 50, 20), y = c(40, 80, 35), z = c(70, 62, 10)) xx        country  x y    z 1  USA    10    40  70 2  UK  50   80   62 3 Canada    20   35   10 I need to arrange this as a new data.frame

[R] How to sort using a predefined criterion

2011-03-08 Thread Vincy Pyne
Dear R helpers, Suppose I have following data.frame. df - data.frame(category = c(treat_A, treat_A, treat_A, treat_A, treat_A, treat_A, treat_A, treat_A, treat_B, treat_B, treat_B, treat_B, treat_B, treat_B, treat_B, treat_B), type = c(AA, , B, AAA, BB, , BBB, AAA, B, AAA, BBB, AA,

[R] Replacing an element in a vector

2011-02-28 Thread Vincy Pyne
Dear R helpers I seem to have one trivial problem but can't find solution to it. Suppose I have following input. A = c(1,  3,  0,  5,  8)  # 3rd element is 0 B = c(100, 30,  0,  25,  40)  # 3rd element is 0 C = A/B C [1] 0.01 0.10  NaN 0.20 0.20 Obviously, I can't

[R] Subtracting elements of data.frame

2011-01-25 Thread Vincy Pyne
Dear R helpers I have a dataframe as df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189)) df    x   y 1  1 102 2 14 500 3  3  40 4 21 101 5 11 189 # Actually I am having dataframe having multiple columns. I am just giving an example. I need to subtract all the rows of df

[R] Sorting data.frame datewise in a descending order

2010-12-30 Thread Vincy Pyne
(mydat$date)) :  undefined columns selected Kindly guide Vincy Pyne [[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

Re: [R] Sorting data.frame datewise in a descending order

2010-12-30 Thread Vincy Pyne
Dear sir, Thanks a lot for your great guidance. It worked fantastically. Regards Vincy Pyne --- On Thu, 12/30/10, Henrique Dallazuanna www...@gmail.com wrote: From: Henrique Dallazuanna www...@gmail.com Subject: Re: [R] Sorting data.frame datewise in a descending order To: Vincy Pyne vincy_p

[R] Changing column names

2010-12-30 Thread Vincy Pyne
Dear R helpers Wish you all a very Happy and Prosperous New Year 2011. I have following query. country = c(US, France, UK, NewZealand, Germany, Austria, Italy, Canada) Through some other R process, the result.csv file is generated as result.csv var1   var2  var3  var4    var5    var6  

[R] Sequence generation in a table

2010-12-09 Thread Vincy Pyne
Dear R helpers I have following input f = c(257, 520, 110). I need to generate a decreasing sequence (decreasing by 100) which will give me an input (in a tabular form) like 257, 157, 57 520, 420, 320, 220, 120, 20 110, 10 I tried the following R code f = c(257, 520, 110) yy =

Re: [R] Sequence generation in a table

2010-12-09 Thread Vincy Pyne
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

Re: [R] Sequence generation in a table

2010-12-09 Thread Vincy Pyne
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

[R] One silly question about tapply output

2010-10-27 Thread Vincy Pyne
Dear R helpers I have a data which gives Month-wise and Rating-wise Rates. So the input file is something like month   rating   rate January    AAA 9.04 February  AAA             9.07 ..

Re: [R] One silly question about tapply output

2010-10-27 Thread Vincy Pyne
: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com Subject: Re: [R] One silly question about tapply output To: Vincy Pyne vincy_p...@yahoo.ca Received: Wednesday, October 27, 2010, 11:28 AM Assign your result to an object and then write out the object as a csv file. For example: x-data.frame

Re: [R] Band-wise Conditional Sum - Actual problem

2010-08-30 Thread Vincy Pyne
. Regards Vincy --- On Fri, 8/27/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Band-wise Sum To: Vincy Pyne vincy_p...@yahoo.ca Cc: r-help@r-project.org Received: Friday, August 27, 2010, 2:36 PM On Aug 27, 2010, at 9:49 AM

Re: [R] Band-wise Conditional Sum - Actual problem

2010-08-30 Thread Vincy Pyne
wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Band-wise Conditional Sum - Actual problem Cc: r-help@r-project.org Received: Monday, August 30, 2010, 2:43 PM On Aug 30, 2010, at 4:05 AM, Vincy Pyne wrote: Dear R helpers, Thanks a lot for your earlier guidance esp. Mr

Re: [R] Band-wise Sum

2010-08-28 Thread Vincy Pyne
learn something from THE WISE like you. Thanks once again Sir. Your help was great and it means a lot to me and for other freshers like me. Regards Vincy Pyne --- On Fri, 8/27/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Band

[R] Band-wise Sum

2010-08-27 Thread Vincy Pyne
Hi I have a large credit portfolio (exceeding 5 borrowers). For particular process I need to add up the exposures based on the bands. I am giving a small test data below. rating - c(A, AAA, A, BBB,AA,A,BB, BBB, AA, AA, AA, A, A, AA,BB,BBB,AA, A, AAA,BBB,BBB, BB, A, BB, A, AA, B,A, AA,