Your lapply is making the call
runif(n=3, min=i)
for i in 1:3. That runif's 3 argument is 'max', with default value 1
so that is equivalent to calling
runif(n=3, min=i, max=1)
When i>max, outside the domain of the family of uniform distributions,
runif returns NaN's.
Bill Dunlap
TIBCO
Thanks, Ista. That explains it.
What I missed is the following "note" in ?lapply:
"This means that the recorded call is always of the form FUN(X[[i]], ...),
with i replaced by the current (integer or double) index. "
That being the case, X[[i]] gets passed to the first available argument,
which
Hi Bert,
On Tue, Nov 14, 2017 at 8:11 PM, Bert Gunter wrote:
> Could someone please explain the following? I did check bug reports, but
> did not recognize the issue there. I am reluctant to call it a bug, as it
> is much more likely my misunderstanding. Ergo my request
Could someone please explain the following? I did check bug reports, but
did not recognize the issue there. I am reluctant to call it a bug, as it
is much more likely my misunderstanding. Ergo my request for clarification:
## As expected:
> lapply(1:3, rnorm, n = 3)
[[1]]
[1] 2.481575 1.998182
> On Jul 30, 2016, at 7:53 PM, roslinazairimah zakaria
> wrote:
>
> Dear r-users,
>
> I would like to use lapply for the following task:
>
> ## Kolmogorov-Smirnov
> ks.test(stn_all[,1][stn_all[,1] > 0],stn_all_gen[,1][stn_all_gen[,1] > 0])
>
Dear r-users,
I would like to use lapply for the following task:
## Kolmogorov-Smirnov
ks.test(stn_all[,1][stn_all[,1] > 0],stn_all_gen[,1][stn_all_gen[,1] > 0])
ks.test(stn_all[,2][stn_all[,2] > 0],stn_all_gen[,2][stn_all_gen[,2] > 0])
ks.test(stn_all[,3][stn_all[,3] >
Dear R list users,
I have three lists of data frames, respectively temp_list, wind_list and
snow_list.
The elements of these three lists are
temp_list$station1, temp_list$station2 and temp_list$station3 with columns date
and temp;
wind_list$station1, wind_list$station2 and wind_list$station3
You need the vectorizes ifelse() instead of if().
Also watch out for order of operations in the last line, and there is
already a base R function named scale(). And spelling of arguments, of
course.
On Saturday, May 30, 2015, Sohail Khan sohai...@gmail.com wrote:
Hi R Gurus,
I am writing a
Hi R Gurus,
I am writing a simple function that take a numeric vector column from a
data frame and scales the vector column with certain criteria. I would
then pass this function to a list of dataframes by lappy.
Question is how do I write a function that works on a numeric vector. My
function
Dear all,
I have a list of arrays :
foo-list(A = c(1,3), B =c(1, 2), C = c(3, 1))
foo
$A
[1] 1 3
$B
[1] 1 2
$C
[1] 3 1
if( foo$C[1] == 1 ) foo$C[1]
lapply(foo, function(x) if(x[1] == 1 ) x )
$A
[1] 1 3
$B
[1] 1 2
$C
NULL
I don't want to list $C NULL in the output. How I can do
On 12.07.2014 15:25, ce wrote:
Dear all,
I have a list of arrays :
foo-list(A = c(1,3), B =c(1, 2), C = c(3, 1))
foo
$A
[1] 1 3
$B
[1] 1 2
$C
[1] 3 1
if( foo$C[1] == 1 ) foo$C[1]
lapply(foo, function(x) if(x[1] == 1 ) x )
$A
[1] 1 3
$B
[1] 1 2
$C
NULL
I don't want to
Hello,
Try the following.
res - lapply(foo, function(x) if(x[1] == 1 ) x )
res[!sapply(res, is.null)]
Hope this helps,
Rui Barradas
Em 12-07-2014 14:25, ce escreveu:
Dear all,
I have a list of arrays :
foo-list(A = c(1,3), B =c(1, 2), C = c(3, 1))
foo
$A
[1] 1 3
$B
[1] 1 2
$C
[1]
I think that removing them is something the OP doesn't understand how to do.
The lapply function ALWAYS produces an output element for every input element.
If this is not what you want then you need to choose a looping structure that
is not so tightly linked to the input, such as a for loop
Thanks Jeff et. all,
This is exactly what I needed.
-Original Message-
From: Jeff Newmiller [jdnew...@dcn.davis.ca.us]
Date: 07/12/2014 10:38 AM
To: Uwe Ligges lig...@statistik.tu-dortmund.de, ce zadi...@excite.com,
r-help@r-project.org
Subject: Re: [R] lapply returns NULL ?
I think
-dortmund.de, ce zadi...@excite.com,
r-help@r-project.org
Subject: Re: [R] lapply returns NULL ?
I think that removing them is something the OP doesn't understand how to do.
The lapply function ALWAYS produces an output element for every input element.
If this is not what you want then you need
Hi,
Try:
x -
c(rep(A,0.1*1),rep(B,0.2*1),rep(C,0.65*1),rep(D,0.05*1))
set.seed(24)
categorical_data - sample(x,1)
set.seed(49)
p_val - runif(1,0,1)
combi - data.frame(V1=categorical_data,V2=p_val)
variables - unique(combi$V1)
res - lapply(levels(variables),function(x){
Hi,
I was trying to use lapply to create a matrix from a list:
uu - list()
uu[[1]] - c(1,2,3)
uu[[2]] - c(3,4,5)
The output I desire is a matrix with 2 rows and 3 columns, so I try:
xx - lapply(uu,rbind)
Obviously, I'm not doing something right, but what!?
[[alternative HTML version
On 14-11-2013, at 16:20, Brian Smith bsmith030...@gmail.com wrote:
Hi,
I was trying to use lapply to create a matrix from a list:
uu - list()
uu[[1]] - c(1,2,3)
uu[[2]] - c(3,4,5)
The output I desire is a matrix with 2 rows and 3 columns, so I try:
xx - lapply(uu,rbind)
Hello,
You are applying rbind to each element of the list, not rbinding it with
the others. Try instead
do.call(rbind, uu)
Hope this helps,
Rui Barradas
Em 14-11-2013 15:20, Brian Smith escreveu:
Hi,
I was trying to use lapply to create a matrix from a list:
uu - list()
uu[[1]] -
Thanks all! So many ways
On Thu, Nov 14, 2013 at 10:35 AM, Rui Barradas ruipbarra...@sapo.pt wrote:
Hello,
You are applying rbind to each element of the list, not rbinding it with
the others. Try instead
do.call(rbind, uu)
Hope this helps,
Rui Barradas
Em 14-11-2013 15:20, Brian
Hi,
the output of lapply() is a list; see ?lapply and ?sapply.
# if you know the length of your list in advance,
# this definition is better:
uu - vector(list, 2)
# list elements
uu[[1]] - c(1,2,3)
uu[[2]] - c(3,4,5)
# some options to achieve what you want:
matrix(unlist(uu), 2, 3, T)
I have a Data Frame that contains, between other things, the following
fields: userX, Time1, Time2, Time3. The number of observations is 2000.
I have a function that has as inputs userX, Time1, Time2, Time3 and return
a data frame with 1 observation and 19 variables.
I want to apply that
Hello,
Maybe you need apply, not lapply. It seems you want to apply() a
function to the first dimension of your data.frame, something like
apply(dat, 1, fun) #apply by rows
Hope this helps,
Rui Barradas
Em 01-09-2013 15:00, Ignacio Martinez escreveu:
I have a Data Frame that contains,
Rui et.al.:
But apply will not work if the data frame has columns of different
classes/types, as appears to be the case here. Viz, from ?apply:
If X is not an array but an object of a class with a non-null
dimhttp://127.0.0.1:12824/help/library/base/help/dim
value (such as a data frame),apply
Oh, another possibility is ?mapply, which I should have pointed out in my
previous reply. Sorry.
-- Bert
On Sun, Sep 1, 2013 at 8:30 AM, Bert Gunter bgun...@gene.com wrote:
Rui et.al.:
But apply will not work if the data frame has columns of different
classes/types, as appears to be the
I hope this reproduceble example helps understand what I'm trying to do.
This is the function:
# Make Data Frame for video actions between given times for user X
DataVideoActionT - function (userX, Time1, Time2, Time3){
#Get data for user X
videoActionsX-subset(videoLectureActions,
Hello,
Your example doesn't really run, but for what I've seen, if your second
data frame is named dat2, something along the lines of
n - nrow(dat2)
res - list(vector, n)
for(i in 1:n){
res[[i]] - with(dat2, DataVideoActionT(anon_ID[i], Time1[i], TimeM[i],
TimeL[i]))
}
do.call(rbind, res)
Thanks a lot Rui. Loops make sense to me. I made one modification to your
code. I have thousands of observation, so I would like to run it in
parallel. This is my reproducible example:
# Make Data Frame for video actions between given times for user X
DataVideoActionT - function (userX, Time1,
Hello,
I have no experience with packages foreach and doMC.
But I believe that paralel computing only pays if the datasets are
really large, due to the setup time. Maybe thousands of observations
is not that large.
Rui Barradas
Em 01-09-2013 22:21, Ignacio Martinez escreveu:
Thanks a lot
Irucka Embry iruckaE at mail2world.com writes:
Hi all, I have a set of 54 files that I need to convert from ASCII grid
format to .shp files to .bnd files for BayesX.
I have the following R code to operate on those files:
library(maptools)
library(Grid2Polygons)
library(BayesX)
Hi all, I have a set of 54 files that I need to convert from ASCII grid
format to .shp files to .bnd files for BayesX.
I have the following R code to operate on those files:
library(maptools)
library(Grid2Polygons)
library(BayesX)
library(BayesXsrc)
library(R2BayesX)
readfunct - function(x)
{
u
Hey guys,
I noticed something curious in the lapply call. I'll copy+paste the
function call here because it's short enough:
lapply - function (X, FUN, ...)
{
FUN - match.fun(FUN)
if (!is.vector(X) || is.object(X))
X - as.list(X)
.Internal(lapply(X, FUN))
}
Notice that lapply
On Sat, Jan 5, 2013 at 7:38 PM, Kevin Ushey kevinus...@gmail.com wrote:
Hey guys,
I noticed something curious in the lapply call. I'll copy+paste the
function call here because it's short enough:
lapply - function (X, FUN, ...)
{
FUN - match.fun(FUN)
if (!is.vector(X) ||
On Jan 5, 2013, at 11:38 AM, Kevin Ushey wrote:
Hey guys,
I noticed something curious in the lapply call. I'll copy+paste the
function call here because it's short enough:
lapply - function (X, FUN, ...)
{
FUN - match.fun(FUN)
if (!is.vector(X) || is.object(X))
X - as.list(X)
Hi David,
Yes, it is - although the SO question was more directed at figuring out why
sapply seemed slower, the question to R-help is more nuanced in is this
coercion really necessary for data.frames?, and I figured it might take
some more knowledge of R internals / the difference between lists
Dear R experts,
I'm using the adehabitatHR package in order to perform a kernel analysis and
estimate the home range of my input data (GPS relocations of 42
individuals).
I've done the analysis for one of the individuals and it worked perfectly
(see code below).
But now I'm trying to use a list
Hello,
I have 2 functions (a and b)
a = function(n) { matrix (runif(n*2,0.0,1), n) }
b = function (m, matrix) {
n=nrow (matrix)
p=ceiling (n/m)
lapply (1:p, function (l,n,m) {
inf = ((l-1)*m)+1
if (lp)
Hello,
When you don't know what's going on, break long instructions into
simpler ones.
R is good at doing a lot in one line, to debug don't do that.
b = function (m, mat) {
n=nrow (mat)
p=ceiling (n/m)
lapply (1:p, function (l,n,m) {
inf = ((l-1)*m)+1
if (lp)
I have a list of suffixes I want to turn into file names with extensions.
suff- c(C1, C2, C3)
paste(filename_, suff[[1]], .ext, sep=)
[1] filename_C1.ext
How do I use lapply() on that call to paste()?
What's the right way to do this:
filenames - lapply(suff, paste, ...)
?
Can I have lapply()
I think you're confused about the need for lapply -- paste is
vectorized so this
paste(filename_, suff, .ext, sep = )
will work. But if you want to use lapply (for whatever reason) try this:
lapply(suff, function(x) paste(filename_, x, .ext, sep = )
Michael
On Wed, Mar 28, 2012 at 2:31 PM, Ed
Thank you, I was confused about that. What exactly is lapply for then,
if R handles this kind of thing automatically? Are there functions that are
not vectorized?
On Wed, Mar 28, 2012 at 1:37 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
I think you're confused about the need for
suff isn't a list, so lapply() isn't the right choice. How about instead:
suff- c(C1, C2, C3)
sapply(suff, function(x)paste(filename_, x, .ext, sep=))
C1C2C3
filename_C1.ext filename_C2.ext filename_C3.ext
On Wed, Mar 28, 2012 at 2:31 PM, Ed
Yes, there are non-vectorized functions e.g, integrate(), or you can use
lapply() to apply a vectorized function to each element of a list (which is not
what suff was) individually:
x - list(1:3, 1:4, 1:5, 2:7)
mean(x) # bad
lapply(x, mean) #good
Michael
On Mar 28, 2012, at 2:44 PM, Ed
On Thu, Mar 29, 2012 at 7:44 AM, Ed Siefker ebs15...@gmail.com wrote:
Thank you, I was confused about that. What exactly is lapply for then,
if R handles this kind of thing automatically? Are there functions that are
not vectorized?
There are, especially ones you write yourself that don't
Hi: I'm sure this is a very easy problem. I've consulted Data Manipulation With
R and the R Book and can't find an answer.
Sample list of data frames looks as follows:
.xx-list(df-data.frame(Var1=rep('Alabama', 400), Var2=rep(c(2004, 2005, 2006,
2007), 400)),
Hi,
On Mon, Mar 12, 2012 at 2:37 PM, Simon Kiss sjk...@gmail.com wrote:
Hi: I'm sure this is a very easy problem. I've consulted Data Manipulation
With R and the R Book and can't find an answer.
Sample list of data frames looks as follows:
.xx-list(df-data.frame(Var1=rep('Alabama', 400),
Hi Simon,
On Mon, Mar 12, 2012 at 2:37 PM, Simon Kiss sjk...@gmail.com wrote:
Hi: I'm sure this is a very easy problem. I've consulted Data Manipulation
With R and the R Book and can't find an answer.
Sample list of data frames looks as follows:
.xx-list(df-data.frame(Var1=rep('Alabama',
Your function doesn't return the new data frame but rather the new
names. Note, e.g.
x - 1:2
names(x) - letters[1:2]
.Last.value # Not x!
Try this:
.xx- lapply(.xx, function(x) {colnames(x)-c('State', 'Year'); x})
or more explicitly
.xx- lapply(.xx, function(x) {colnames(x)-c('State',
Thanks both! That solves ! You've made a very happy newbie!
Simon
On 2012-03-12, at 2:52 PM, Sarah Goslee wrote:
Hi Simon,
On Mon, Mar 12, 2012 at 2:37 PM, Simon Kiss sjk...@gmail.com wrote:
Hi: I'm sure this is a very easy problem. I've consulted Data Manipulation
With R and the R Book
Hi hi,
It is much easier to deal with lists than a large number of separate
objects. So the first answer to your question
How can I apply a function to a list of variables.
.. might be to convert your list of variables to a regular list.
Instead of ...
monday - 1:3
tuesday - 4:7
wednesday -
Hi
Can someone help me with this?
How can I apply a function to a list of variables.
something like this
listvar=list(Monday,Tuesday,Wednesday)
func=function(x){x[which(x=10)]=NA}
lapply(listvar, func)
were
Monday=[213,56,345,33,34,678,444]
Tuesday=[213,56,345,33,34,678,444]
...
in my case
On 08.11.2011 17:59, Ana wrote:
Hi
Can someone help me with this?
How can I apply a function to a list of variables.
something like this
listvar=list(Monday,Tuesday,Wednesday)
This is a list of length one character vectors rather than a list of
variables.
Hi:
Here's another way of doing this on the simplified version of your example:
L - vector('list', 3) # initialize a list of three components
## populate it
for(i in seq_along(L)) L[[i]] - rnorm(20, 10, 3)
## name the components
names(L) - c('Monday', 'Tuesday', 'Wednesday')
## replace
Dear all,
I have a function that recognizes the following format for timestamps
%Y-%m-%d %H:%M:%S
my function takes two input arguments the TimeStart and TimeEnd
I would like to help me create the right list with pairs of TimeStart and
TimeEnd which I can feed to lapply (I am using mclapply
Provide some sample data. For instance, a data frame with two columns and the
function.
On Oct 31, 2011, at 6:37 PM, Alaios ala...@yahoo.com wrote:
Dear all,
I have a function that recognizes the following format for timestamps
%Y-%m-%d %H:%M:%S
my function takes two input arguments
alaios wrote:
Dear all,
I have a function that recognizes the following format for timestamps
%Y-%m-%d %H:%M:%S
my function takes two input arguments the TimeStart and TimeEnd
I would like to help me create the right list with pairs of TimeStart and
TimeEnd which I can feed to lapply
Dear all I have wrote the following line
return(as.vector(lapply(as.data.frame(data),min,simplify=TRUE)));
I want the lapply to return a vector as it returns a list with elements as
shown below
List of 30001
$ V1: num -131
$ V2: num -131
$ V3: num -137
$ V4: num -129
$ V5
do.call(rbind, lapply(...))
HTH,
D.
On Sat, Oct 22, 2011 at 1:44 AM, Alaios ala...@yahoo.com wrote:
Dear all I have wrote the following line
return(as.vector(lapply(as.data.frame(data),min,simplify=TRUE)));
I want the lapply to return a vector as it returns a list with elements as
shown
Hi R users
I was wondering on how to use lapply co when the applied function has a
conditional statement and the output is a 'growing' object.
See example below:
list1 - list('A','B','C')
list2 - c()
myfun - function(x,list2)
{
one_elem - x
cat('one_elem= ', one_elem, '\n')
random -
Hi Lorenzo,
On Thu, May 5, 2011 at 8:38 AM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote:
Hi R users
I was wondering on how to use lapply co when the applied function has a
conditional statement and the output is a 'growing' object.
See example below:
list1 - list('A','B','C')
list2 -
Good day,
My question is: Does the lapply function guarantee a particular sequence in
which elements are mapped? And, are we guaranteed that lapply will always be
sequential (i.e. never map elements in parallel) ?
The reason I ask is if I use lapply with the mapping function set to
something
On 20/04/2011 7:26 AM, Dean Marks wrote:
Good day,
My question is: Does the lapply function guarantee a particular sequence in
which elements are mapped? And, are we guaranteed that lapply will always be
sequential (i.e. never map elements in parallel) ?
No.
The reason I ask is if I use
Hi all,
I find myself sometimes in the situation where I lapply over a list and
in the particular function I'd like to use the name and or position of
the respective list item. What I usually do is to use mapply on the list
and the names of the list / a position list:
o - list(A=1:3, B=1:2, C=1)
Hi there,
I have a problem about lapply, strsplit, and accessing list elements,
which I don't understand or cannot solve:
I have e.g. a character vector with three elements:
x = c(349/077,349/074,349/100,349/117,
340/384.2,340/513,367/139,455/128,D13/168,
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Dick Harray
Sent: Friday, February 04, 2011 7:37 AM
To: r-help@r-project.org
Subject: [R] lapply, strsplit, and list elements
Hi there,
I have a problem about lapply
04, 2011 8:37 AM
To: r-help@r-project.org
Subject: [R] lapply, strsplit, and list elements
Hi there,
I have a problem about lapply, strsplit, and accessing list elements,
which I don't understand or cannot solve:
I have e.g. a character vector with three elements:
x = c(349/077,349
Try this:
strsplit(x, /\\d+\\.\\d+,|/\\d+,|/\\d+)
On Fri, Feb 4, 2011 at 1:37 PM, Dick Harray tomdhar...@gmail.com wrote:
Hi there,
I have a problem about lapply, strsplit, and accessing list elements,
which I don't understand or cannot solve:
I have e.g. a character vector with three
On Fri, Feb 4, 2011 at 1:27 PM, Greg Snow greg.s...@imail.org wrote:
Try this:
x - c(349/077,349/074,349/100,349/117,
+ 340/384.2,340/513,367/139,455/128,D13/168,
+ 600/437,128/903,128/904)
library(gsubfn)
out - strapply(x, '([0-9]+)(?=/)')
out
[[1]]
[1] 349 349 349
Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111
-Original Message-
From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
Sent: Friday, February 04, 2011 12:22 PM
To: Greg Snow
Cc: Dick Harray; r-help@r-project.org
Subject: Re: [R] lapply, strsplit, and list
Hello All,
I have a toy dataframe like this. It has 8 columns separated by tab.
NameSampleIDAl1 Al2 X Y R Th
rs191191A1 A B 0.999 0.090.780.090
abc928291 A1 B J 0.3838 0.3839 0.028 0.888
abcnab
Hi Sashi,
On Thu, Dec 9, 2010 at 9:44 AM, Sashi Challa cha...@ohsu.edu wrote:
Hello All,
I have a toy dataframe like this. It has 8 columns separated by tab.
Name SampleID Al1 Al2 X Y R Th
rs191191 A1 A B 0.999 0.09 0.78
On Dec 9, 2010, at 12:44 PM, Sashi Challa wrote:
Hello All,
I have a toy dataframe like this. It has 8 columns separated by tab.
NameSampleIDAl1 Al2 X Y R Th
rs191191A1 A B 0.999 0.090.780.090
abc928291 A1 B
, December 09, 2010 10:07 AM
To: Sashi Challa
Cc: r-help@R-project.org
Subject: Re: [R] lapply getting names of the list
Hi Sashi,
On Thu, Dec 9, 2010 at 9:44 AM, Sashi Challa cha...@ohsu.edu wrote:
Hello All,
I have a toy dataframe like this. It has 8 columns separated by tab.
Name SampleID
On Dec 9, 2010, at 2:21 PM, David Winsemius wrote:
On Dec 9, 2010, at 12:44 PM, Sashi Challa wrote:
Hello All,
I have a toy dataframe like this. It has 8 columns separated by tab.
NameSampleIDAl1 Al2 X Y R Th
rs191191A1 A B
Yes, that is what I what...
Thanks.
Feng
On Wed, Oct 13, 2010 at 6:38 AM, Michael Bedward
michael.bedw...@gmail.comwrote:
Hello Feng,
I think you just want this...
lapply(A, function(x) apply(x[,,-c(1,2)], c(1,2), mean))
Michael
On 13 October 2010 04:00, Feng Li feng...@stat.su.se
Dear R,
I have a silly question concerns with *apply. Say I have a list called A,
A - list(a = array(1:20, c(2, 2, 5)), b = array(1:30, c(2, 3, 5)))
I wish to calculate the mean of A$a, and A$b w.r.t. their third dimension so
I did
lapply(A,apply,c(1,2),mean)
Now if I still wish to do the
Hello Feng,
I think you just want this...
lapply(A, function(x) apply(x[,,-c(1,2)], c(1,2), mean))
Michael
On 13 October 2010 04:00, Feng Li feng...@stat.su.se wrote:
Dear R,
I have a silly question concerns with *apply. Say I have a list called A,
A - list(a = array(1:20, c(2, 2, 5)),
Hi all,
I have a dataset with several variables, each of which is a separate
column. For each variable, I want to produce a boxplot and include the
name of the variable (ie, column name) on each plot.
I have included a sample dataset below. Can someone tell me where I am
going wrong?
Shawn -
Does this example help? (Please don't use cbind when creating
a data frame, since it first creates a matrix, which means everything
must be of the same mode.)
var1 = rnorm(1000)
var2 = rnorm(1000)
TimePeriod = rep((LETTERS[1:4]), 250)
my.data = data.frame(var1,var2,TimePeriod)
Many thanks Phil, that does help.
If I could ask a follow-up, how do I put each plot in its own device
window? Right now, all I get is the boxplot for var2 (var1 gets
overwritten?). I tried putting quartz() before the boxplot command but
got an error message.
Cheers,
Shawn
On 22/06/10
Hello Shawn,
Does this do what you want? I'm assuming you want to look at each
plot, so I added a call to par().
###
my.data - data.frame(var1=rnorm(1000), var2=rnorm(1000),
TimePeriod=factor(rep((LETTERS[1:4]), 250)))
str(my.data)
lapply(names(my.data[ , 1:2]), function(y) {
old.par -
Thanks Josh,
I do want to see each plot. I took your code and modified it (below) and
it appears to do what I wanted:
my.data - data.frame(var1=rnorm(1000), var2=rnorm(1000),
TimePeriod=factor(rep((LETTERS[1:4]), 250)))
str(my.data)
lapply(names(my.data[ , 1:2]), function(y) {
quartz()
Try this:
library(lattice)
bwplot(values ~ TimePeriod | ind, cbind(stack(my.data), TimePeriod =
my.data$TimePeriod))
On Tue, Jun 22, 2010 at 1:45 PM, Shawn Morrison
shawn.morri...@dryasresearch.com wrote:
Hi all,
I have a dataset with several variables, each of which is a separate
column.
William,
Try a rolling join in data.table, something like this (untested) :
setkey(Data, UnitID, TranDt)# sort by unit then date
previous = transform(Data, TranDt=TranDt-1)
Data[previous,roll=TRUE]# lookup the prevailing date before, if any,
for each row within that row's UnitID
Henrique,
thx, your suggestion worked perfectly fine for me.
On 01.06.2010, at 23:01, Henrique Dallazuanna wrote:
lapply(mydf[-6], ccf, y = mydf[6])
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read
I have a dataset of property transactions that includes the
transaction ID (TranID), property ID (UnitID), and transaction date
(TranDt). I need to create a data frame (or data table) that includes
the previous transaction date, if one exists.
This is an easy problem in SQL, where I just run a
On Wed, Jun 2, 2010 at 10:29 PM, William Rogers whroger...@gmail.com wrote:
I have a dataset of property transactions that includes the
transaction ID (TranID), property ID (UnitID), and transaction date
(TranDt). I need to create a data frame (or data table) that includes
the previous
Dear all,
I am trying to avoid a for loop here and wonder if the following is possible:
I have a data.frame with 6 columns and i want to get a cross-correlogram (by
using ccf) . Obivously ccf only accepts two columns at once and then returms a
list.
In fact, with a for loop i´d do the
Try this:
lapply(mydf[-6], ccf, y = mydf[6])
On Tue, Jun 1, 2010 at 5:50 PM, Bunny, lautloscrew.com
bu...@lautloscrew.com wrote:
Dear all,
I am trying to avoid a for loop here and wonder if the following is
possible:
I have a data.frame with 6 columns and i want to get a
Bunny, lautloscrew.com wrote:
Dear all,
I am trying to avoid a for loop here and wonder if the following is
possible:
I have a data.frame with 6 columns and i want to get a
cross-correlogram (by using ccf) . Obivously ccf only accepts two
columns at once and then returms a list. In fact,
Dear R users,
I have created a function f of n, a and b : f(n,a,b)
I would like to apply this function several times to some values of n. a and
b are held constant. I was thinking of using lapply. How can I do this ?
Thank you very much
Randall
[[alternative HTML version deleted]]
lapply(yourList, f, a=1, b=2)
On Tue, Apr 13, 2010 at 9:11 AM, Randall Wrong randall.wr...@gmail.comwrote:
Dear R users,
I have created a function f of n, a and b : f(n,a,b)
I would like to apply this function several times to some values of n. a
and
b are held constant. I was thinking of
Thank you Jim
2010/4/13 jim holtman jholt...@gmail.com
lapply(yourList, f, a=1, b=2)
On Tue, Apr 13, 2010 at 9:11 AM, Randall Wrong
randall.wr...@gmail.comwrote:
Dear R users,
I have created a function f of n, a and b : f(n,a,b)
I would like to apply this function several times to
another thought possibly
fn = function(n, a=1, b=3) return(n*(a+b))
sapply(1:3, fn)
--
View this message in context:
http://n4.nabble.com/lapply-function-with-arguments-tp1838373p1838506.html
Sent from the R help mailing list archive at Nabble.com.
I have split my original dataframe to generate a list of dataframes each of
which has 3 columns of factors and a 4th column of numeric data.
I would like to use lapply to apply the fitdistr() function to only the 4th
column (x$isi) of the dataframes in the list.
Is there a way to do this or am
I have split my original dataframe to generate a list of dataframes each of
which has 3 columns of factors and a 4th column of numeric data.
I would like to use lapply to apply the fitdistr() function to only the 4th
column (x$isi) of the dataframes in the list.
Is there a way to do this or am
It would have been nice if you had at least posted what the structure of
myList is. Assuming that this is the list of your data frames, then the
following might work:
lapply(myList, function(x) fitdistr(x$isi,
densfun='gamma',start=list(scale=1, shape=2)))
On Sun, Mar 7, 2010 at 7:30 PM, Dgnn
library(MASS)
dat - data.frame(
col1=as.factor(sample(1:4, 100, T)),
col2=as.factor(sample(1:4, 100, T)),
col3=as.factor(sample(1:4, 100, T)),
isi=rnorm(100)
)
dat - split(dat, as.factor(sample(1:3, 100, T)))
lapply(dat, function(x, densfun) fitdistr(x$isi, densfun), 'normal')
I'm a bit confused on how to use lapply with a data.frame.
For example.
lapply(data, function(x) print(x))
WHAT exactly is passed to the function. Is it each ROW in the data
frame, one by one, or each column, or the entire frame in one shot?
What I want to do apply a function to each row
-project.org] On Behalf Of
Noah Silverman [n...@smartmediacorp.com]
Sent: 28 February 2010 12:37
To: r-help@r-project.org
Subject: [R] lapply with data frame
I'm a bit confused on how to use lapply with a data.frame.
For example.
lapply(data, function(x) print(x))
WHAT exactly is passed
1 - 100 of 161 matches
Mail list logo