[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

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 pa

[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. library(plyr

[R] Maintaining Column names while writing csv file.

2012-07-18 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 both

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

2012-07-18 Thread Vincy Pyne
command To: "Vincy Pyne" 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 <- as.character(unique(dat1$nam

[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

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

2012-07-03 Thread Vincy Pyne
Dear Mr Newmiller and Mr Oettli, Thanks a lot for your valuable guidance. Task is done. Thanks again. Regards Vincy --- On Wed, 7/4/12, Jeff Newmiller wrote: From: Jeff Newmiller Subject: Re: [R] How to use Sys.time() while writing a csv file name To: "Vincy Pyne" , r-help@r-p

[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 - # My

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

2012-05-22 Thread Vincy Pyne
N? To: "Vincy Pyne" , "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 you are doing mean(16, trim = 18) What you want is

[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 generati

[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 appr

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Vincy Pyne
quot;Vincy Pyne" 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 wrote: > Dear R helpers > > Suppose &

[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] Constructing a data.frame from csv files

2012-01-11 Thread Vincy Pyne
required data.frame. Thanks again. With warm regards Vincy --- On Wed, 1/11/12, jim holtman wrote: From: jim holtman Subject: Re: [R] Constructing a data.frame from csv files To: "Vincy Pyne" Cc: r-help@r-project.org Received: Wednesday, January 11, 2012, 1:49 PM The error message s

[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 = c("in

[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 estima

[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",

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 wrote: From: S Ellison Subject: RE: [R] Question regarding dnorm() To: "Vincy Pyne" , "r-help@r-project.org" Received: Wednesday, September 14, 2011, 11:37 AM You have calculated dens

[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 i.e.

[R] Autocorrelation using acf

2011-08-25 Thread Vincy Pyne
: Prof Brian Ripley Subject: Re: [R] Autocorrelation using library(tseries) To: "Vincy Pyne" 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() in package tseries: it is in stats. And the au

[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

Re: [R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
-project.org Cc: "Vincy Pyne" 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:   x = c(44,46,46,47,45,43,45,44)   y = c(44,43,41,41,4

Re: [R] Correlation discrepancy

2011-08-23 Thread Vincy Pyne
] Correlation discrepancy To: r-help@r-project.org Cc: "Vincy Pyne" 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:   x = c(44,46,46,47,4

[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] Meaning of "%%"

2011-07-13 Thread Vincy Pyne
7/13/11, ONKELINX, Thierry wrote: From: ONKELINX, Thierry Subject: RE: [R] Meaning of "%%" To: "Vincy Pyne" , "r-help@r-project.org" Received: Wednesday, July 13, 2011, 10:13 AM help("%%") ---

[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 m

[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 growt

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 i

[R] Value of 'pi'

2011-05-29 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]] _

[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 fr

[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]]

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 wrote: From: Henrique Dallazuanna Subject: Re: [R] Ordering data.frame based on class To: "Vincy Pyne" Cc: r-help@r-project.org Received: Monday, March 28, 2011, 9:02 PM Try thi

[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

[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 var

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

2011-03-25 Thread Vincy Pyne
will be executed outside the loop. Once this is generated, writing of the csv file should not be problem outside the loop. Regards Vincy --- On Fri, 3/25/11, Ista Zahn wrote: From: Ista Zahn Subject: Re: [R] Appending data to a data.frame and writing a csv To: "Vincy Pyne" Cc

[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, 56813.14859,4012356.056,1419501.179,210853

Re: [R] Correlation for no of variables

2011-03-21 Thread Vincy Pyne
refer to the packages you have suggested. Thanks again Vincy --- On Mon, 3/21/11, Peter Langfelder wrote: From: Peter Langfelder Subject: Re: [R] Correlation for no of variables To: "Vincy Pyne" Cc: r-help@r-project.org Received: Monday, March 21, 2011, 4:50 PM On Mon, Mar 21, 2011

[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 can

[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

[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 ve

Re: [R] Identifying unique pairs

2011-03-12 Thread Vincy Pyne
3/12/11, Petr Savicky wrote: From: Petr Savicky 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 > &

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 wrote: From: Dennis Murphy Subject: Re: [R] Identifying unique pairs To: "Vincy Pyne" Cc: r-help@r-project.org Received: Saturday, March 12, 2011, 11:45 AM Hi

[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  

[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)

Re: [R] How to use conditional statement

2011-03-10 Thread Vincy Pyne
t;  if (val3 == "Monthly") val <- val1 >  else val <- val2 > > For a simple calculation like this I'd probably use the former; if the > calculation got more complex I'd prefer the latter. > > Duncan Murdoch > >> >> Single "=" is f

[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 tr

[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

[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",

[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 di

[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] 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   

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 wrote: From: Henrique Dallazuanna Subject: Re: [R] Sorting data.frame datewise in a descending order To: "Vincy Pyne" Cc: r-help@r-project.or

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

2010-12-30 Thread Vincy Pyne
n I tried                                     mydat.sort <- mydat[order(mydat$date)] > mydat.sort <- mydat[order(mydat$date)] Error in `[.data.frame`(mydat, order(mydat$date)) :  undefined columns selected Kindly guide Vincy Pyne [[alternative HTML version deleted]] ___

Re: [R] Sequence generation in a table

2010-12-09 Thread Vincy Pyne
, Petr PIKAL wrote: From: Petr PIKAL Subject: Re: [R] Sequence generation in a table To: "Vincy Pyne" 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 y

Re: [R] Sequence generation in a table

2010-12-09 Thread Vincy Pyne
rbing 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 wrote: From: Jan van der Laan Subject: Re: [R] Sequence generation in a table To: r-help@r-project.org, vincy_p...@yahoo.ca Received: Thursday, December 9, 2010,

[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 = matrix(da

Re: [R] One silly question about "tapply output"

2010-10-27 Thread Vincy Pyne
: Re: [R] One silly question about "tapply output" To: "Vincy Pyne" 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(rating=rep(letters[1:3],2),rate=runif(1:6)) # example

[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] Band-wise Conditional Sum - Actual problem

2010-08-30 Thread Vincy Pyne
HTH, Dennis   --- On Mon, 8/30/10, David Winsemius wrote: From: David Winsemius 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, > > Th

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

2010-08-30 Thread Vincy Pyne
sorry for any mis-communication in my earlier mail. I could test the reply sent to me earlier by Winsemius Sir only today as I was traveling over weekends. Also, I have tried to go through earlier emails dealing with such conditional sums. Unfortunately, I couldn't understand as I have rec

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 wrote: From: David Winsemius Subject: Re: [R] Band-wise Sum To: "Vincy Pyne" Cc

[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","