Displaying 20 results from an estimated 10000 matches similar to: "Correct use of ddply with own function"
2012 Jul 11
1
do I need plyr, apply or something else?
Dear all,
This is what I'd like to do (I have an implementation using for loops, which I designed before I realised just how slow R is at executing them - this process currently takes days to run).
I have a large dataframe containing corporate bond data, columns are:
BondID
Date (goes back 5years)
Var1
Var2
Term2Maturity
What I want to do is this:
1) For each bond, at each given date,
2011 Nov 29
2
aggregate syntax for grouped column means
I am calculating the mean of each column grouped by the variable 'id'.
I do this using aggregate, data.table, and plyr. My aggregate results
do not match the other two, and I am trying to figure out what is
incorrect with my syntax. Any suggestions? Thanks.
Here is the data.
myData <- structure(list(var1 = c(31.59, 32.21, 31.78, 31.34, 31.61, 31.61,
30.59, 30.84, 30.98, 30.79, 30.79,
2013 Jul 18
1
Bland Altman summary stats for all column combinations
Hello,
I have the following data.frame
structure(list(Study = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
2010 Dec 06
3
[plyr] Question regarding ddply: use of .(as.name(varname)) and varname in ddply function
Dear R-Helpers:
I am using trying to use *ddply* to extract min and max of a particular
column in a data.frame. I am using two different forms of the function:
## var_name_to_split is a string -- something like "var1" which is the name
of a column in data.frame
ddply( df, .(as.name(var_name_to_split)), function(x) c(min(x[ , 3] , max(x[
, 3]))) ## fails with an error - case 1
ddply(
2012 Jul 25
2
reshape -> reshape 2: function cast changed?
Hi,
I used to use reshape and moved to reshape2 (R 2.15.1). Now I tried some of my older scripts and was surprised that my cast function wasn't working like before.
What I did/want to do:
1) Melt a dataframe based on a vector specifying column names as measure.vars. Thats working so far:
dfm <- melt(df, measure.vars=n, variable_name = "species", na.rm = FALSE)
2) Recast the
2010 Jul 29
3
Fwd: duplicates
-- Eredeti üzenet --
Feladó: Dévaványai Agamemnón <devavanyai@citromail.hu>Címzett: r-hel@r-project.org, r-hel@r-project.orgElküldve: 2010. július 29. 16:29Tárgy : duplicates
Sorry!
I try it again
Dear R Users!
I have a dataframe with duplicatecases. Var1 duplicated by var2.
var1 var2 var3 var4 var5
1 4 500 1 2
1 3 200 2 5
1
2013 Mar 06
6
Ggplot2: Moving legend, change fill and removal of space between plots when using grid.arrange() possible use of facet_grid?
Hi,
# For publications, I am not allowed to repeat the axes. I have tried to
remove the axes using:
# yaxt="n", but it did not work. I have not understood how to do this in
ggplot2. Can you help me?
# I also do not want loads of space between the graphs (see below script
with Dummy Data).
# If I could make it look like the examples on the (nice) examples page:
#
2008 Jul 16
2
Group level frequencies
Dear List,
I have Multi-level Data
i= Indivitual Level
g= Group Level
var1= First Variable of interest
var2= Second Variable of interest
and I want to count the frequency of "var1" and "var2" on the group
level.
I found a way, but there must be a much simpler way.
data.ml <-
data.frame(i=c(1:8),g=as.factor(c(1,1,1,2,2,3,3,3)),var1=c(3,3,3,4,4,4,4
,4),
2012 Jul 17
1
weighted mean by week
Hello!
I wrote a code that works, but it looks ugly to me - it's full of loops.
I am sure there is a much more elegant and shorter way to do it.
Thanks a lot for any hints!
Dimitri
# I have a data frame:
x<-data.frame(group=c("group1","group2","group1","group2"),
myweight=c(0.4,0.6,0.4,0.6),
2004 Aug 17
5
Bug in colnames of data.frames?
Hi,
I am using R 1.9.1 on on i686 PC with SuSE Linux 9.0.
I have a data.frame, e.g.:
> myData <- data.frame( var1 = c( 1:4 ), var2 = c (5:8 ) )
If I add a new column by
> myData$var3 <- myData[ , "var1" ] + myData[ , "var2" ]
everything is fine, but if I omit the commas:
> myData$var4 <- myData[ "var1" ] + myData[ "var2" ]
the name
2009 Sep 22
3
converting a character vector to a function's input
Hi all, I have been trying to solve this problem and have had no luck so far.
I have numeric vectors VAR1, VAR2, and VAR3 which I am trying to cbind. I also have a character vector "VAR1,VAR2,VAR3". How do I manipulate this character vector such that I can input a transformed version of the character vector into cbind and have it recognize that I'm trying to refer to my numeric
2014 Aug 21
2
pregunta
Buenas noches Javier y José,
Estoy en contra de usar attach(), asi que propongo la siguiente alternativa
con with():
# paquete
require(epicalc)
# los argumentos en ... pasan de epicalc:::cc
# ver ?cc para mas informacion
foo <- function(var1, var2, var3, ...){
or1 <- cc(var1, var2, ...)
or2 <- cc(var1, var3, ...)
list(or1 = or1, or2 = or2)
}
# datos
x <-
2010 Dec 20
2
Turning a Variable into String
I would like to know how to turn a variable into a string. I have tried
as.symbol and as.name but it doesnt work for what I'd like to do
Essentially, I'd like to feed the function below with two variables. This
works fine in the bit working out number of elements in each variable.
In the print(sprintf("OK with %s and %s\n", var1, var2)) line I would like
var1 and var2 to be
2006 Mar 02
1
CCF and Lag questions
I am new to R and new to time series modeling.
I have a set of variables (var1, var2, var3, var4, var5) for which I have
historical yearly data.
I am trying to use this data to produce a prediction of var1, 3 years into
the future.
I have a few basic questions:
1) I am able to read in my data, and convert it to a time series format
using 'ts.'
data_ts <- ts(data, start = 1988, end =
2010 Feb 05
2
sum a particular column by group
Dear all,
I have a table like this:
> eds
R.ID Region Gender Agegr Time nvisits
1 1 A F 60--64 1:00 1
2 2 O F 55--59 1:20 1
3 3 O F 55--59 3:45 3
4 4 S M 60--64 1:10 3
5 5 W F 55--59 12:30 1
6
2012 Jul 01
2
list to dataframe conversion-testing for identical
HI R help,
I was trying to get identical data frame from a list using two methods.
#Suppose my list is:
listdat1<-list(rnorm(10,20),rep(LETTERS[1:2],5),rep(1:5,2))
#Creating dataframe using cbind
dat1<-data.frame(do.call("cbind",listdat1))
colnames(dat1)<-c("Var1","Var2","Var3")
#Second dataframe conversion
2006 Jan 13
2
find mean of a list of timeseries
Can someone please give me a clue how to 're'write this so I dont need
to use loops.
a<-ts(matrix(c(1,1,1,10,10,10,20,20,20),nrow=3),names=c('var1','var2','var3'))
b<-ts(matrix(c(2,2,2,11,11,11,21,21,21),nrow=3),names=c('var1','var2','var3'))
2008 May 02
2
Coercing by/tapply to data.frame for more than two indices?
Dear Colleagues,
Apologies for a long email to ask what I feel may be a very simple
question; I figure it's better to overspecify my situation.
I was asked a question, recently, by a colleague in my department
about pre-aggregating variables, i.e., computing the mean of defined subsets
of a data frame. Naturally, I thought of the 'by' and 'tapply' functions, as
2009 May 20
1
Comparing spatial distributions - permutation test implementation
Hello everyone,
I am looking at the joint spatial distribution of 2 kinds of organisms
(estimated on a grid of points) and want to test for significant
association or dissociation.
My first question is: do you know a nice technique to do that,
considering that I have a limited number of points (36) but that they
are repeated (4 times)? I did GLMs to test for correlations between
the
2010 Mar 18
1
Using a function to consolidate variables
Dear List,
I'm getting the error: object of type 'closure' is not subsettable
And am not sure how to get around the problem. I've included two
short code sets below. One that shows what I want to do and works,
but without using the function much, and another that tries to use the
function but causes the error.
# THIS WORKS AND SHOWS WHAT I'D LIKE TO DO
a <- c(1,2,3)
b