Frank S.
De: Bert Gunter
Enviat el: dilluns, 26 de setembre de 2016 23:18:52
Per a: Ista Zahn
A/c: Frank S.; r-help@r-project.org
Tema: Re: [R] Using lapply in R data table
... and just for fun, here's an alternative in which mapply() is used
to vectorize switch(); again, whet
... and just for fun, here's an alternative in which mapply() is used
to vectorize switch(); again, whether you like it may be just a matter
of taste, although I suspect it might be less efficient than ifelse(),
which is already vectorized:
DT <- within(DT,
exposure <- {
Ista:
Aha -- now I see the point. My bad. You are right. I was careless.
However, cut() with ifelse() might simplify the code a bit and/or make
it more readable. To be clear, this is just a matter of taste; e.g.
using your data and a data frame instead of a data table:
> DT <- within(DT,
On Mon, Sep 26, 2016 at 2:48 PM, Bert Gunter wrote:
> I thought that that was a typo from the OP, as it disagrees with his
> example. But the labels are arbitrary, so in fact cut() will do it
> whichever way he meant.
I don't see how cut will do it, at least not conveniently. Consider
this slight
I thought that that was a typo from the OP, as it disagrees with his
example. But the labels are arbitrary, so in fact cut() will do it
whichever way he meant.
-- Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Ber
On Mon, Sep 26, 2016 at 1:59 PM, Bert Gunter wrote:
> This seems like a job for cut() .
I thought that at first two, but the middle group shouldn't be .87 but rather
exposure" = "2007-01-01" - "fini"
so, I think cut alone won't do it.
Best,
Ista
>
> (I made DT a data frame to avoid loading the
This seems like a job for cut() .
(I made DT a data frame to avoid loading the data table package. But I
assume it would work with a data table too, Check this, though!)
> DT <- within(DT, exposure <-
> cut(fini,as.Date(c("2000-01-01","2006-01-01","2006-06-30","2006-12-21")),
> labels= c(1,.87,
Hi Frank,
lapply(DT) iterates over each column. That doesn't seem to be what you want.
There are probably better ways, but here is one approach.
DT[, exposure := vector(mode = "numeric", length = .N)]
DT[fini < as.Date("2006-01-01"), exposure := 1]
DT[fini >= as.Date("2006-01-01") & fini <= as.D
Dear all,
I have a R data table like this:
DT <- data.table(
id = rep(c(2, 5, 7), c(3, 2, 2)),
fini = rep(as.Date(c('2005-04-20', '2006-02-19', '2006-10-08')), c(3, 2, 2)),
group = rep(c("A", "B", "A"), c(3, 2, 2)) )
I want to construct a new variable "exposure" defined as follows:
1) I
Hi Team,
I am new to using apply function in R.
I want to find out the empirical quantiles of all items in a list.
## Fitting Kernal Density function
Emp_Marginals<-apply(M_Diff_Final,2,kde)
### Simulated variables
Sim_Cop<-abs(rmvnorm(1,mean=apply(M_Diff_Final,2,mean),sigma=cov(M_Diff_Final)
Winsemius wrote:
Subject: Re: [R] Using lapply when there are dependencies
Cc: r-help@r-project.org
Date: Thursday, May 28, 2015, 7:02 AM
On May
27, 2015, at 4:34 PM, blue honour via R-help wrote:
> Hi all,
>
> Let's say I have
a vector:
>
>
vv<-c(1,2,3)
&
For loops are not slow. Inefficient memory management in for loops is slow.
Feel free to preallocate your output vectors and write for loops to your
heart's content. If you really want speed you can write this in C++ using Rcpp
[1]. If your f() is a standard digital filter algorithm this has al
Hi
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of blue
> honour via R-help
> Sent: Thursday, May 28, 2015 1:34 AM
> To: r-help@r-project.org
> Subject: [R] Using lapply when there are dependencies
>
> Hi all,
>
> Let
On May 27, 2015, at 4:34 PM, blue honour via R-help wrote:
> Hi all,
>
> Let's say I have a vector:
>
> vv<-c(1,2,3)
>
>
> And suppose I have a function f(a,b), which is a function of 2 scalar inputs.
> I would like to evaluate this function separately for each element of the vv
> vector wh
Hi all,
Let's say I have a vector:
vv<-c(1,2,3)
And suppose I have a function f(a,b), which is a function of 2 scalar inputs. I
would like to evaluate this function separately for each element of the vv
vector while the second input to f( ) will be the previous output from f( ).
So, the valu
Given three TermDocumentMatrix, text1, text2 and text3, I'd like to
calculate word frequency for each of them into a data frame and rbind all
the data frames. Three are sample - I have hundreds in reality so I need to
functionalize this.
It's easy to calculate word freq for one TDM:
apply(x,
On Jan 10, 2014, at 2:04 AM, Long Vo wrote:
Hi R users,
I need to apply a function on a list of vectors. This is simple when
I use
functions that returns only one numerical value such as 'mean' or
'variance'. Things get complex when I use functions returning a list
of
value, such as 'acf'
Hi R users,
I need to apply a function on a list of vectors. This is simple when I use
functions that returns only one numerical value such as 'mean' or
'variance'. Things get complex when I use functions returning a list of
value, such as 'acf'.
In the following example I first create a list of v
function(x)
data.frame(x[colnames(x)!="prov"],prov=recode(x$prov,"'QUE'='QC';'Quebec'='QC'")))
A.K.
- Original Message -
From: Simon Kiss
To: arun
Cc:
Sent: Friday, November 9, 2012 9:39 AM
Subject: Re: [R] using lapp
#5 5 17 QC
#6 6 7 AB
#7 7 6 AB
#8 8 21 AB
#9 9 5 AB
#10 10 1 AB
A.K.
----- Original Message -
From: Simon Kiss
To: arun
Cc:
Sent: Friday, November 9, 2012 9:39 AM
Subject: Re: [R] using lapply with recode
Hi there:
None of these suggestions do the work. I tried J
Original Message -
From: Simon Kiss
To: r-help@r-project.org
Cc:
Sent: Thursday, November 8, 2012 10:06 PM
Subject: [R] using lapply with recode
Hello:
Forgive me, this is surely a simple question but I can't figure it out, having
consulted the help archives and "Data Manipulation Wit
a prov
#1 1 Quebec
#2 2 Quebec
#3 3 Quebec
#4 4 Quebec
#5 5 Quebec
#6 6 AB
#7 7 AB
#8 8 AB
#9 9 AB
#10 10 AB
A.K.
- Original Message -
From: Simon Kiss
To: r-help@r-project.org
Cc:
Sent: Thursday, November 8, 2012 10:06 PM
Subject: [R] using lapply
you need to return 'x' as the last statement of the lapply.
Sent from my iPad
On Nov 8, 2012, at 22:06, Simon Kiss wrote:
> Hello:
> Forgive me, this is surely a simple question but I can't figure it out,
> having consulted the help archives and "Data Manipulation With R" (Spector).
> I have
Hello:
Forgive me, this is surely a simple question but I can't figure it out, having
consulted the help archives and "Data Manipulation With R" (Spector).
I have a list of 11 data frames with one common variable in each (prov). I'd
like to use lapply to go through and recode one particular leve
.org] On Behalf Of
rex.dw...@syngenta.com
Sent: Thursday, March 10, 2011 8:47 AM
To: lig...@statistik.tu-dortmund.de; arun.kumar.s...@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] using lapply
But no one answered Kushan's question about performance
implications of for-loop vs lapply.
With apologie
ware
wdunlap tibco.com
>
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Uwe Ligges
> Sent: Thursday, March 10, 2011 4:38 AM
> To: Arun Kumar Saha
> Cc: r-help@r-project.org
> Subject: Re: [R] using la
Uwe Ligges
Sent: Thursday, March 10, 2011 4:38 AM
To: Arun Kumar Saha
Cc: r-help@r-project.org
Subject: Re: [R] using lapply
On 10.03.2011 08:30, Arun Kumar Saha wrote:
> On reply to the post
> http://r.789695.n4.nabble.com/using-lapply-td3345268.html
Hmmm, can you please reply to the origi
On 10.03.2011 08:30, Arun Kumar Saha wrote:
On reply to the post
http://r.789695.n4.nabble.com/using-lapply-td3345268.html
Hmmm, can you please reply to the original post and quote it?
You mail was not recognized to be in the same thread as the message of
the original poster (and hence I was
On 10.03.2011 03:46, Kushan Thakkar wrote:
I have a function with the follow signare:
apply.strategy(instr, strat)
where instr and strat are both objects of classes instrument and strategy
respectively.
I want to apply this function to a list that holds objects of the class
instrument.
Curr
On reply to the post
http://r.789695.n4.nabble.com/using-lapply-td3345268.html
Dear Kushan, this may be a good start:
## assuming 'instr.list' is your list object and you are applying
my.strat() function on each element of that list, you can use lapply
function as
lapply(instr.list, function(x)
I have a function with the follow signare:
apply.strategy(instr, strat)
where instr and strat are both objects of classes instrument and strategy
respectively.
I want to apply this function to a list that holds objects of the class
instrument.
Currently I am doing this by explicit looping:
for
Hi again,
I have spent the last couple of days trying to build a function that will
allow me to add to the multiple plots that I created with your advice. I
have changed to
plot(ln.o2con~lnbm,data=df)
in my function and this works fine.
On an individual plot I can fit quantile regressions u
The data= argument to plot only makes sense if the first
argument is a formula. So if you change the plot command
in your function to
plot(ln.o2con~lnbm,data=df)
you might get what you want. But I would suggest you take a
look at the plot produced by
library(lattice)
xyplot(ln.o2con~l
Hi,
I would like to be able to plot data from each of the sp.id on individual
plots. At the moment I can plot all the data on one graph with the following
commands but I cannot figure out how to get individual graph for each sp.id.
i<- function(df)plot(lnbm,ln.o2con,data=df)
j<- lapply(split(one
Yes thank you Jorge :working:
-
Anna Lippel
--
View this message in context:
http://n4.nabble.com/Using-lapply-with-two-lists-tp1692883p1692898.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
htt
Hi Anna,
Here is a suggestion:
# creating L1
L1 <- lapply(1:5, function(x) matrix(rnorm(10), ncol = 2))
L1
# creating L2
L2 <- lapply(1:5, function(x) sample(5, 2))
L2
# defining a function
foo <- function(x, y) list(x[-y,])
# result
mapply(foo, L1, L2)
HTH,
Jorge
On Fri, Mar 26, 2010 at 5:3
-5672
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of anna
Sent: Friday, March 26, 2010 5:35 PM
To: r-help@r-project.org
Subject: [R] Using lapply with two lists
Hello guys,
I have a list L1 of matrix. I have another list L2 with
Hello guys,
I have a list L1 of matrix. I have another list L2 with the same number of
elements representing the row of the L matrix that I want to delete
(L1[[i]][-L2[[i]],]) but I can't do this with lapply as it iterates through
L1 (first argument) and not L2. Any idea?
-
Anna Lippel
--
V
OK, that looks a good suggestion. Though it is a bit of a step towards loops
and counting ...
Thanks a lot.
Regards
JS
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: Tue 2/5/2008 4:51 PM
To: john seers (IFR)
Cc: R Help
Subject: Re: [R] Using lapply
e lapply to plot the
> data (or whatever) and be able to slap a label on it so I can keep track
> of what I am doing.
>
> Regards
>
> John Seers
>
>
>
>
> -Original Message-
> From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
> Sent: 05 February 2008
plot the
data (or whatever) and be able to slap a label on it so I can keep track
of what I am doing.
Regards
John Seers
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: 05 February 2008 16:17
To: john seers (IFR)
Cc: R Help
Subject: Re: [R] Using lapply and
9
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
- Original Message -
From: "john seers (IFR)" <[EMAIL PROTECTED]>
To: "R Help" <[EMAIL PROTECTED]>
Sent: Tuesday, February 05, 2008 5:05
The problem is your data is in wide format and you want it in long format.
See ?reshape and also see the reshape package. In your example, ?stack
is sufficient:
library(lattice)
xyplot(values ~ seq_along(values) | ind, data = stack(people))
On Feb 5, 2008 11:05 AM, john seers (IFR) <[EMAIL PRO
Hello All
Using lapply and ending up with lists of lists I often end up in the
position of not having the names of the list passed by lapply. So, if I
am doing something like a plot, and I would like the title to reflect
which plot it is, I cannot easily do it. So I find myself doing some
unstru
lic University of Leuven
>
> Address: Kapucijnenvoer 35, Leuven, Belgium
> Tel: +32/(0)16/336899
> Fax: +32/(0)16/337015
> Web: http://med.kuleuven.be/biostat/
> http://www.student.kuleuven.be/~m0390867/dimitris.htm
>
>
> - Original Message -----
> From: "
dimitris.htm
- Original Message -
From: "dxc13" <[EMAIL PROTECTED]>
To:
Sent: Tuesday, January 08, 2008 6:11 PM
Subject: [R] using lapply()
>
> useR's,
>
> I am trying to find a quick way to change some values in a list that
> are
> subjec
useR's,
I am trying to find a quick way to change some values in a list that are
subject to a condition to be NA. Consider the 3x1 matrix:
delta <- matrix(c(2.5,2.5,1), nrow = 1)
And consider the list named v that has 3 elements
> v
v[[1]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
47 matches
Mail list logo