[R] Fast function for each row of a data.table

2014-07-23 Thread Aurélien Philippot
Dear R experts, I have the following data.table: dt<- data.table(A=rep(1:5), B=c(20:24), C=rep(30:34), target.name=c("A","B", "C","B","A"), target.column=c(1,2,3,2,1), target.value=rep(NA,5)) Columns A, B and C are the variables of interest. For each row, I want to get the value of the variable

[R] Numerical solution

2014-01-08 Thread Aurélien Philippot
Dear R experts, I want to use numerical methods to solve a complex problem. Here is a very simple example that gives an idea of what I would like to do. This example could be solved by hand, but I am interested in finding a numerical solution in R. Let's say that I have the following equation:

[R] Problem with uniroot.all

2013-12-26 Thread Aurélien Philippot
Dear R experts, I am trying to find all the solutions of an equation. Here is an example: integrand1<- function(x){1/x*dnorm(x)} integrand2<- function(x){1/(2*x-50)*dnorm(x)} integrand3<- function(x,C){ cd<- 1/(x+C) return(cd) } res<- function(C){ ce<-integrate(integrand1, lower=1, upper=

[R] Simplifying an expression with an integral

2013-12-24 Thread Aurélien Philippot
Dear R experts, I am computing the following integral. [image: \int_{1,100} \frac{1}{x+Max(x-50,0)} g(x)dx], where g is the density of the standard normal, and [1,100] is the domain. 1) I use the following code which works fine: integrand1<- function(x){1/x*dnorm(x)} integrand2<- function(x){1/(2

Re: [R] Inconsistent computation of an integral

2013-12-20 Thread Aurélien Philippot
of max(x-50,0), which returns a scalar. > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > > > > -Original Message- > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf > > Of Aurélien Philippot >

[R] Inconsistent computation of an integral

2013-12-19 Thread Aurélien Philippot
Dear R experts, I computed the same integral in two different ways, and find different values in R. The difference is due to the max function that is part of the integrand. In the first case, I keep it as such, in the second case, I split it in two depending on the values of the variable of integra

Re: [R] Problem to solve an integral equation

2013-12-17 Thread Aurélien Philippot
put function changes sign? 2013/12/17 David Winsemius > > On Dec 17, 2013, at 8:53 AM, Aurélien Philippot wrote: > > > Dear R experts, > > > > I am trying to find numerical solutions for an integral equation. > > > > > > Here is an example: &

[R] Problem to solve an integral equation

2013-12-17 Thread Aurélien Philippot
Dear R experts, I am trying to find numerical solutions for an integral equation. Here is an example: I started by defining the integrand, as a function of x and C, where x is the variable of integration and C is the parameter I am interested in: integrand<- function(C,x){-((10*x)^(-1)-(1

Re: [R] Help: problem converting character to numeric

2012-03-14 Thread Aurélien PHILIPPOT
thanks for your suggestions, which work. In addition, I updated Rstudio to the latest version and my old code works again. Best, Aurelien 2012/3/14 Petr Savicky > On Wed, Mar 14, 2012 at 03:07:19PM -0700, Aurélien PHILIPPOT wrote: > > Dear R experts, > > I have a dataframe impo

[R] Help: problem converting character to numeric

2012-03-14 Thread Aurélien PHILIPPOT
Dear R experts, I have a dataframe imported from a csv file (with read.csv). Here is an example: mm<- c("19860228", "19860331","19860430","19860531") id<-c("1","1","1","1") re<- c("C","0.25", "0.98", "1.34") mret<-data.frame(mm, id, re) mret<-as.numeric(as.character(mret

Re: [R] Problem with xtable- rescaling a table

2012-02-04 Thread Aurélien PHILIPPOT
> Would this go outside or inside the "center" block? > >> > \begin{sidewaystable}[ht] >> > >> > \begin{center} >> > >> > \begin{tabular}{ccc} > > Secondly, what combination of arguments is giving you LaTeX w

Re: [R] Problem with xtable- rescaling a table

2012-02-01 Thread Aurélien PHILIPPOT
> \end{sidewaystable} > > Alternatively, since the size of the table is determined by the size of the > text in the table, you can just tell LaTeX to use a smaller font, e.g. > > <>= > print(outfile, include.rownames=F, floating.environment='sidewaystable', > s

[R] Problem with xtable- rescaling a table

2012-01-31 Thread Aurélien PHILIPPOT
Dear R users, I am new to Latex and I am using the R package xtable to generate tables. I want to produce a table that is very long. in the landscape format, but I would need to rescale the table so that it fits in the page. xtable enables me to have the landscape format, but I cannot rescale it,

Re: [R] Group several variables and apply a function to the group

2011-12-04 Thread Aurélien PHILIPPOT
ornia, USA > http://www.fws.gov/redbluff/rbdd_jsmp.aspx > > *From:* Aurélien PHILIPPOT > *To:* R-help@r-project.org > *Sent:* Sunday, December 4, 2011 12:32 PM > *Subject:* [R] Group several variables and apply a function to the group > > Dear R-experts, > I am struggli

[R] Group several variables and apply a function to the group

2011-12-04 Thread Aurélien PHILIPPOT
Dear R-experts, I am struggling with the following problem, and I am looking for advice from more experienced R-users: I have a data frame with 2 identifying variables (comn and mi), and an output variable (x). comn is a variable for a company and mi is a variable for a month. comn<-c("abc", "abc"

Re: [R] Problem subsetting: undefined columns

2011-12-02 Thread Aurélien PHILIPPOT
thanks Michael. I played with your suggestion to get the output in the format I wanted, and I found the following that works fine: sub<-d[, which(colnames(d) %in% v) ] Aurelien 2011/12/2 R. Michael Weylandt < michael.weyla...@gmail.com> > How about this? > > d[, v[v %in% colnames(d)]] > > Mich

Re: [R] Problem subsetting: undefined columns

2011-12-02 Thread Aurélien PHILIPPOT
I know there is at least one match between the 2. Initially, I tried something in the spirit: sub<- subset(d, colnames(d) %in% v) but I could not make it work properly. Best, Aurelien 2011/12/2 Paul Hiemstra > On 12/02/2011 07:20 AM, Aurélien PHILIPPOT wrote: > > Dear R-users, &

[R] Problem subsetting: undefined columns

2011-12-02 Thread Aurélien PHILIPPOT
Dear R-users, -I am new to R, and I am struggling with the following problem. -I am repeating the following operations hundreds of times, within a loop: I want to subset a data frame by columns. I am interested in the columns names that are given by the rows of another data frame that was built i

[R] Efficient way to do a merge in R

2011-10-03 Thread Aurélien PHILIPPOT
Dear all, I am new in R and I have been faced with the following problem, that slows me down a lot. I am short of ideas to circumvent it. So, any help would be highly appreciated: I have 2 dataframes x and y. x is very big (70 million observations), whereas y is smaller (30 observations). Al