[R] How to use current value of variable in function definition?

2009-07-02 Thread Allan Engelhardt
Must be the heat or something but I can't get my brain into gear and figure out how to get something like if (1) { c - 1; foo - function () print(c); } c - 2 foo() to print 1, not 2. (The real life example is a little more complex, but you get the idea. I don't want the variable c in the

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread William Dunlap
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Allan Engelhardt Sent: Thursday, July 02, 2009 9:47 AM To: r-help@r-project.org Subject: [R] How to use current value of variable in function definition? Must be the heat or something but I can't get

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread Allan Engelhardt
() a Allan On 02/07/09 18:28, William Dunlap wrote: From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Allan Engelhardt Sent: Thursday, July 02, 2009 9:47 AM To: r-help@r-project.org Subject: [R] How to use current value of variable in function definition

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread Mark Wardle
Hi. I've stared at your code for a number of minutes and can't understand what you're trying to achieve here. It looks as if you're fighting scope - it may be worth refactoring your approach to simplify matters. Otherwise, it sounds like a recipe for obfuscation! What are you trying to do really?

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread Allan Engelhardt
On 02/07/09 21:02, Mark Wardle wrote: Hi. I've stared at your code for a number of minutes and can't understand what you're trying to achieve here. It looks as if you're fighting scope - it may be worth refactoring your approach to simplify matters. Otherwise, it sounds like a recipe for

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread Peter Dalgaard
Mark Wardle wrote: Hi. I've stared at your code for a number of minutes and can't understand what you're trying to achieve here. It looks as if you're fighting scope - it may be worth refactoring your approach to simplify matters. Otherwise, it sounds like a recipe for obfuscation! What are you

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread William Dunlap
From: Allan Engelhardt [mailto:all...@cybaea.com] Sent: Thursday, July 02, 2009 11:12 AM To: William Dunlap Cc: r-help@r-project.org Subject: Re: [R] How to use current value of variable in function definition

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread Nordlund, Dan (DSHS/RDA)
...@r-project.org] On Behalf Of William Dunlap Sent: Thursday, July 02, 2009 2:44 PM To: Allan Engelhardt Cc: r-help@r-project.org Subject: Re: [R] How to use current value of variable in function definition? From: Allan Engelhardt [mailto:all

Re: [R] How to use current value of variable in function definition?

2009-07-02 Thread Gabor Grothendieck
The proto package generalizes this to an OO approach based on the prototype or object-based model of OO. This corresponds to the previous code: library(proto) p - proto(c = 1, foo = function(.) print(.$c)) p$foo() # 1 # but now we can also create q which overrides c # while inheriting foo from

[R] How to use subset in lm function

2009-06-29 Thread Hongwei Dong
Hi, I'm using R to do a time series analysis. In the model, I use the lags of some variables. such the lags of the variables have different length, I just can't use them directly in the lm function. Intuitively, I feel that subset might be useful, but I do not know how to use it. Anyone can give

Re: [R] How to use subset in lm function

2009-06-29 Thread milton ruser
Like this? x-1:100 y-runif(100) df-data.frame(cbind(x,y)) mycoef.list-NULL for (i in 10:65) { mycoef-coef(lm(y~x, data=subset(df, x %in% 1:i)))[2] mycoef.list -c(mycoef.list, mycoef) } hist(mycoef.list) regards milton brazil=toronto On Mon, Jun 29, 2009 at 2:50 PM, Hongwei Dong

Re: [R] How to use subset in lm function

2009-06-29 Thread Gabor Grothendieck
The dyn package (and also the dynlm package) can be used for this. library(dyn) y - ts(1:10) dyn$lm(y ~ lag(y, -1)) On Mon, Jun 29, 2009 at 2:50 PM, Hongwei Dongpdxd...@gmail.com wrote: Hi, I'm using R to do a time series analysis. In the model, I use the lags of some variables. such the lags

[R] how to use lapplyBy function of doBy package

2009-06-08 Thread Mao Jianfeng
Dear Ruser's I want to substitute each NA by the group mean of which the NA is belonging to. For example, substitute the first record of traits NA by the mean of BSPy01-10 in the dummy dataframe. I have ever tried to solve this problem by using doBy package. But, I failed. I ask for the advice

Re: [R] how to use lapplyBy function of doBy package

2009-06-08 Thread Gabor Grothendieck
Here are four ways: # using lapplyBy - DF is already sorted by group library(doBy) f - function(x) { x$traits[is.na(x$traits)] - mean(x$traits, na.rm = TRUE) x } do.call(rbind, lapplyBy(~ group, DF, f)) # using by - same f as before do.call(rbind, by(DF, DF$group, f)) # using

Re: [R] How to use write.csv(x=zoo.object), and how to let the first column corret?

2009-05-01 Thread Gabor Grothendieck
Try this: library(zoo) z - zoo(cbind(a = 1:4, b = 5:8), Sys.time() + 0:3 * 3600) z0 - zoo(coredata(z), format(time(z), %m-%d-%y %H:%M:%S)) write.zoo(z0, sep = ,) Index,a,b 05-01-09 17:59:31,1,5 05-01-09 18:59:31,2,6 05-01-09 19:59:31,3,7 05-01-09 20:59:31,4,8 On Fri, May 1, 2009 at 5:11

[R] How to use write.csv(x=zoo.object), and how to let the first column corret?

2009-05-01 Thread Qianfeng Li
Use  write.csv to output a zoo object, and found the first column in excel like:  (08-10-16 13:12:00)   How to make it look like : 10/16/2008 13:12:00 ?     write.csv(x=zoo.object)   Thanks! [[alternative HTML version deleted]] __

[R] How to use cubic spline coefficients from termstrc package?

2009-04-14 Thread Chirantan Kundu
Hi, I'm using the cubic splines from termstrc package. I invoked the splines_estim function with a group of 43 bonds. It computes 6 knot points and returns values for alpha1 to alpha7. My question is how to use these alpha1 to alpha7 in the equation of yield? For example, if I'm trying to find

[R] How to use termstrc functions?

2009-03-20 Thread Chirantan Kundu
Hi, I'm trying to use the package termstrc. However I cannot figure out how to invoke helper functions like create_cashflows_matrix create_maturities_matrix. Even when I try to invoke those with the data supplied with the package (say, corpbonds), it throws error saying Error in as.vector(x,

Re: [R] How to use termstrc functions?

2009-03-20 Thread David Winsemius
Got code? On Mar 20, 2009, at 8:15 AM, Chirantan Kundu wrote: I'm trying to use the package termstrc. However I cannot figure out how to invoke helper functions like create_cashflows_matrix create_maturities_matrix. Even when I try to invoke those with the data supplied with the package (say,

Re: [R] How to use termstrc functions?

2009-03-20 Thread Chirantan Kundu
Here it goes - library(termstrc) ISIN - vector() ISIN[1]-IN0020080019 ISIN[2]-IN0020020163 MATURITYDATE-as.Date(c(20081231,20101231),%Y%m%d) STARTDATE-as.Date(c(20010101,20020101),format=%Y%m%d) COUPONRATE-c(8.24,7.95) PRICE-(50,100) ACCRUED-c(5,2) TODAY-c(Sys.Date(),Sys.Date()) mybonds -

Re: [R] How to use termstrc functions?

2009-03-20 Thread David Winsemius
On Mar 20, 2009, at 10:15 AM, Chirantan Kundu wrote: Here it goes - library(termstrc) ISIN - vector() ISIN[1]-IN0020080019 ISIN[2]-IN0020020163 MATURITYDATE-as.Date(c(20081231,20101231),%Y%m%d) STARTDATE-as.Date(c(20010101,20020101),format=%Y%m%d) COUPONRATE-c(8.24,7.95) PRICE-(50,100)

Re: [R] How to use termstrc functions?

2009-03-20 Thread David Winsemius
Besides needing a grouped structure and not calling that function with a group name, your sub-structure does not seem complete when compared with the AAA group within the example dataset; str(allbonds) # your structure List of 1 $ mybonds:List of 7 ..$ ISIN: chr [1:2]

Re: [R] How to use termstrc functions?

2009-03-20 Thread Chirantan Kundu
Thanks for the help. RATING NAME are not required for this call as par documentation. About the CASHFLOWS I'm not sure as I'm going to call create_cashflows_matrix which is supposed to return me the cashflow matrix. Do I still need to have the CASHFLOWSlist in the structure? On Fri, Mar 20, 2009

Re: [R] How to use termstrc functions?

2009-03-20 Thread David Winsemius
How could I (or anyone for that matter) possibly answer that question? David Winsemius, MD Heritage Laboratories West Hartford, CT On Mar 20, 2009, at 1:07 PM, Chirantan Kundu wrote: Thanks for the help. RATING NAME are not required for this call as par documentation. About the CASHFLOWS

Re: [R] How to use termstrc functions?

2009-03-20 Thread Chirantan Kundu
Actually I was looking for someone who has some experience in using the package. Anyway, thanks for your input. On Fri, Mar 20, 2009 at 10:51 PM, David Winsemius dwinsem...@comcast.net wrote: How could I (or anyone for that matter) possibly answer that question? David Winsemius, MD Heritage

Re: [R] How to use termstrc functions?

2009-03-20 Thread David Winsemius
There is probably a greater density of potential users on the SIG- Finance mailing list. I still think you attribute special powers to that function that the authors never build into it. It does not predict the future. It doesn't even simulate the future. It just reformats into a matrix the

[R] how to use axes=FALSE to get multple plots?

2009-02-10 Thread Dan Kelley
I am trying to plot two things on one graph, with a y-axis at the left for one variable, and a y-axis at the right, for the other variable. I thought I could do as follows par(mar=rep(4.5, 4)) plot(0:10, 10:20) par(new=TRUE) plot(0:10, 100:110, axes=FALSE) axis(4) but this writes both y-axis

Re: [R] how to use axes=FALSE to get multple plots?

2009-02-10 Thread Duncan Murdoch
Dan Kelley wrote: I am trying to plot two things on one graph, with a y-axis at the left for one variable, and a y-axis at the right, for the other variable. I thought I could do as follows par(mar=rep(4.5, 4)) plot(0:10, 10:20) par(new=TRUE) plot(0:10, 100:110, axes=FALSE) axis(4) but this

Re: [R] how to use axes=FALSE to get multple plots?

2009-02-10 Thread Dan Kelley
Duncan Murdoch-2 wrote: ...Are you really sure you want a graph with two different scales on it? Thanks, Duncan. I'll use mtext. It is common for people in my research area to put several axes on plots. The top two panels from library(oce) data(ctd) plot(ctd) shows this. Actually,

[R] How to use different title in a loop

2008-12-08 Thread Xinxin Yu
Hi all, I want to draw n plots whose titles are Main effect of X_i, i= 1, 2, ..., n, respectively. More specifically, I use: par(mfrow = c(n/2, 2)) for ( i in 1:n) { plot(1:J, y[i, 1: J], main = 'Main effect of X_i') } This gives me a series of plots with the common title with a

Re: [R] How to use different title in a loop

2008-12-08 Thread Aval Sarri
see ?paste main = paste (Main effect of , variable) par(mfrow = c(n/2, 2)) for ( i in 1:n) { plot(1:J, y[i, 1: J], main = 'Main effect of X_i') } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do

[R] HOW to use the Hosmer–Lemeshow test ‏ in R

2008-09-25 Thread leo_wa
i want to know how to use the Hosmer–Lemeshow test‏ in R. Can anyone show me the program to me and tell me how to use it? -- View this message in context: http://www.nabble.com/HOW-to-use-the-Hosmer%E2%80%93Lemeshow-test%E2%80%8F-in-R-tp19675283p19675283.html Sent from the R help mailing list

Re: [R] HOW to use the Hosmer–Lemeshow test ‏ in R

2008-09-25 Thread Frank E Harrell Jr
leo_wa wrote: i want to know how to use the Hosmer–Lemeshow test‏ in R. Can anyone show me the program to me and tell me how to use it? Please read the archives as this question has been posed many times in the past few years. My answer is always the same: read the following article and see

[R] how to use chisq.test with 2 row matrix having 0 in it?

2008-08-21 Thread Sun, Ying [BSD] - HGD
Hi, I am working on calculating X^2 for some matrix (most of them have either two rows or 2 columns) by using chisq.test in R. However when there are 0s in the matrix, chisq.test does not work. For example: elements - matrix( c( 0, 0, 9, 5, 71, 168), nr = 2 ) elements

[R] how to use substring match as condition?

2008-05-29 Thread Albert Vilella
Hi, How can I use a substring match as a condition in a subset command? Sth like this: subset(input, field1==blah1 field2==blah2) # but now with substring match in field2 subset(input, field1==blah1 field3 *substringmatch* blah3) I've tried with gsub, but it won't work: subset(input,

Re: [R] how to use substring match as condition?

2008-05-29 Thread john seers (IFR)
] how to use substring match as condition? Hi, How can I use a substring match as a condition in a subset command? Sth like this: subset(input, field1==blah1 field2==blah2) # but now with substring match in field2 subset(input, field1==blah1 field3 *substringmatch* blah3) I've tried with gsub

Re: [R] how to use substring match as condition?

2008-05-29 Thread Charles C. Berry
On Thu, 29 May 2008, Albert Vilella wrote: Hi, How can I use a substring match as a condition in a subset command? Perhaps subset(input, field1==blah1 regexpr(blah2,field3) != -1 ) ?? Study in example(gsub) the regexpr example and in ?gsub the 'Value'

Re: [R] How to use classwt parameter option in RandomForest

2008-05-22 Thread Liaw, Andy
The weights given should correspond to the ordering of levels(y) where y contains the class labels. If in doubt, you can also give the classwt as a named vector (e.g., classwt=c(B=3, A=2, C=1)). Search in the R-help archive to see other options and why you probably shouldn't use classwt. Andy

[R] How to use classwt parameter option in RandomForest

2008-05-20 Thread Nagu
Hi, I am trying to model a dataset with the response variable Y, which has 6 levels { Great, Greater, Greatest, Weak, Weaker, Weakest}, and predictor variables X, with continuous and factor variables using random forests in R. The variable Y acts like an ordinal variable, but I recoded it as

[R] how to use the result obtained from Deal Package

2008-04-28 Thread man4ish
Hi , I am using the deal package (for learning and comparing the bayesian network). I am getting the negative score for the heuristics search , i am not able to interpret the result . more negative(smaller) is better or larger value is better.Please Help me out .I will be thankful to you.

[R] How to use the optim function if the length of the objective function is greater than 1?

2008-04-26 Thread kakul modani
Hi, Please help me out with this.Im a new user of R. Thanks [[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

Re: [R] How to use the optim function if the length of the objectivefunction is greater than 1?

2008-04-26 Thread Charles Annis, P.E.
: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of kakul modani Sent: Saturday, April 26, 2008 10:40 AM To: r-help@r-project.org Subject: [R] How to use the optim function if the length of the objectivefunction is greater than 1? Hi, Please help me out with this.Im a new user of R. Thanks

[R] how to use a function in aggregate which accepts matrix and outputs matrix?

2008-04-17 Thread zhihuali
Dear netters, suppose I have a matrix X [1,] 'c1' 'r6' '150'[2,] 'c1' 'r4' '70'[3,] 'c1' 'r2' '20'[4,] 'c1' 'r5' '90'[5,] 'c2' 'r2' '20'[6,] 'c3' 'r1' '10'I want to apply some funciton to groups of rows by the first column.If the function is just to calculate the average X[,3], it will

Re: [R] how to use a function in aggregate which accepts matrix and outputs matrix?

2008-04-17 Thread jim holtman
Does something like this work for you? It is using 'lapply' with the indices of the rows: x - matrix(c( 'c1' , 'r6', '150', 'c1' , 'r4' ,'70' ,'c1' , 'r2' ,'20', + 'c1' , 'r5' ,'90', 'c2' ,'r2' ,'20', 'c3' , 'r1' ,'10'), byrow=TRUE, ncol=3) # use lapply result - lapply(split(seq(nrow(x)),

[R] How to use glm.predict properly

2008-03-25 Thread Diego Cesar
I'm having a little trouble with the glm.predict function. I read the other answers related to this question (the lm.predict question), but i'm still receiving the same warnings, then i thought i didnt got it right. Warning: 'newdata' had 87 rows but variable(s) found have 263 rows Commands:

[R] How to use R from .NET

2008-03-25 Thread James Guo
I an R-beginner. I would like to use/call some functions/objects of R from microsoft .NET environment. I was wondering whether or not it is possible. If yes, could you please give me some suggestions on how to approach it (any documentation on this)? Thanks! -James [[alternative

Re: [R] How to use a reserved word in italics in an expression

2008-02-17 Thread Michael Kubovy
Delightfully straightforward! Thanks. On Feb 16, 2008, at 5:15 PM, Duncan Murdoch wrote: On 16/02/2008 4:51 PM, Michael Kubovy wrote: Dear R-helpers, label2 - expression(paste(italic(attraction function:), 'slope')) Error: unexpected 'function' in label2 -

Re: [R] How to use a reserved word in italics in an expression

2008-02-16 Thread Duncan Murdoch
On 16/02/2008 4:51 PM, Michael Kubovy wrote: Dear R-helpers, label2 - expression(paste(italic(attraction function:), 'slope')) Error: unexpected 'function' in label2 - expression(paste(italic(attraction function How do I tell R that in this case I don't want 'function' to be

[R] how to use anova() to test the sum of coefficients in nlme package

2008-01-26 Thread shirley zhang
Dear R-help, In nlme package, anova () can be used to test the difference between two coefficients as shown on page 225 of Mixed Effects Models in S and S-Plus: anova(fm2BW.lme, L = c(Time:Diet2 = 1, Time:Diet3 = -1)) Now my question is instead of test the difference between two coefficients,

[R] how to use different variable to store values with different length in a loop

2008-01-18 Thread Jack Luo
Hi, List I am trying to use variables named A1, A2, ..., A100 to store some values, each variable could store some values with different length, how can I achieve this? Thanks, Jack [[alternative HTML version deleted]] __

Re: [R] how to use R for Beta Negative Binomial

2008-01-07 Thread Duncan Murdoch
Nasser Abbasi wrote: Duncan Murdoch [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Why did you change the parameters? If you used the same ones as above, you get sghyper(a=-1, k=-1, N=5) $title [1] Generalized Hypergeometric $Mean [1] 0.2

[R] how to use R for Beta Negative Binomial

2008-01-06 Thread Nasser Abbasi
I think I should have posted this question here as well. I am posting my question here since it is R related. Please see below. I originally posted this to sci.stat.math Nasser Abbasi [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I think R documentation is a bit hard for me to

Re: [R] how to use R for Beta Negative Binomial

2008-01-06 Thread Duncan Murdoch
On 06/01/2008 9:36 AM, Nasser Abbasi wrote: I think I should have posted this question here as well. I am posting my question here since it is R related. Please see below. I originally posted this to sci.stat.math Nasser Abbasi [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]

[R] How to use R to estimate a model which has two sets of lagged time series independent variables

2007-12-13 Thread Suen, Michael
Hi, I would like to use R to estimate the following model: X(t) = a + b1*X(t-1) + b2*X(t-2) + c1*Y(t) + c2*Y(t-1) + c3*Y(t-2) Is there any R function that performs this type of estimation? I know that if I only have one time series (i.e. lagged value of X) on the right hand side then there are

Re: [R] How to use R to estimate a model which has two sets of laggedtime series independent variables

2007-12-13 Thread Pfaff, Bernhard Dr.
Hi, I would like to use R to estimate the following model: X(t) = a + b1*X(t-1) + b2*X(t-2) + c1*Y(t) + c2*Y(t-1) + c3*Y(t-2) Is there any R function that performs this type of estimation? I know that if I only have one time series (i.e. lagged value of X) on the right hand side then there are

Re: [R] How to use R to estimate a model which has two sets of lagged time series independent variables

2007-12-13 Thread Gabor Grothendieck
If you don't need a complex error structure then the dyn package (and also the dynlm package) can do it. Using R's builtin EuStockMarkets time series: library(dyn) z - as.zoo(EuStockMarkets) mod1 - dyn$lm(DAX ~ lag(DAX, -(1:2)) + lag(FTSE, -(0:2)), z) mod1 # compare to model without FTSE mod2 -

[R] How to use a specifical graphical device (e.g., png, bmp) with R version 2.5.1under Linux

2007-10-22 Thread HU,ZHENGJUN
Hi All, I am now using R version 2.5.1 under Linux (Red Hat), and have some problems to use some graphical devices (e.g., png, jpeg, bmp and so on). Can you tell/teach me how to solve the problem(s)? See below for details. (1) I make sure that package:grDevices is on the list using

[R] How to use lm() with both subset and weights argument

2007-10-19 Thread Alp Atıcı
I'd like to fit a linear model on a subset of a data frame with given weights. I am curious how the lm() works when both subset and weights argument is specified. Let me give an example: filter is a boolean vector of length the same as one column of df, my dataframe. What I want is the linear

[R] how to use normalmixEM to get correct result?

2007-10-14 Thread bgchen
Dear R-Users, I have a large number of data(54000) and the field of data is 50 to 2.0e9. I want to use normalmixEM (package:mixtools) to fit them in finite mixture narmal distributions,but get some mistakes.I don't know which steps make the error. I have used the following

Re: [R] how to use \Sexpr{} with sweave

2007-10-09 Thread cryan
)? For what command is this an option? Thanks. --Chris Ryan Original message Date: Sat, 6 Oct 2007 22:38:04 -0400 (EDT) From: [EMAIL PROTECTED] Subject: [R] how to use \Sexpr{} with sweave To: [EMAIL PROTECTED] I'm trying to learn Sweave. So far things are going well with the chunks

Re: [R] how to use \Sexpr{} with sweave

2007-10-07 Thread Friedrich Schuster
Hi, this works for me (R 2.5.1, Linux): echo=false= data(airquality) library(ctest) kruskal.test(Ozone ~ Month, data = airquality) @ Wir haben hier also \Sexpr{nrow(airquality)} Datenzeilen in airquality. This works \Sexpr{2+6} I think the error is in your latex setup, not in R or Sweave.

Re: [R] how to use \Sexpr{} with sweave

2007-10-07 Thread Duncan Murdoch
[EMAIL PROTECTED] wrote: I'm trying to learn Sweave. So far things are going well with the chunks of code identified by = But I'm having trouble with the in-line text use of \Sexpr. Here is a short example .Rnw file: \documentclass[12pt]{article} \usepackage[margin=1.25in]{geometry}

Re: [R] how to use \Sexpr{} with sweave

2007-10-07 Thread cryan
Duncan-- The .tex file that you describe as output of Sweave(test.Rnw) is what I had expected. But I get this .tex file when I run Sweave: \documentclass[12pt]{article} \usepackage[margin=1.25in]{geometry} \usepackage{graphicx} \usepackage{Sweave} \begin{document} \begin{Schunk}

Re: [R] how to use \Sexpr{} with sweave

2007-10-07 Thread cryan
I think some inadvertent cutting and pasting may have made my last e-mail difficult to interpret. Here is the .tex file I get as output of Sweaving my .Rnw file. Note that \Sexpr{2+6} appears where you get (and I want) simply 8. \documentclass[12pt]{article}

<    1   2   3   4   5   6