similar to: [plyr] Question regarding ddply: use of .(as.name(varname)) and varname in ddply function

Displaying 20 results from an estimated 100 matches similar to: "[plyr] Question regarding ddply: use of .(as.name(varname)) and varname in ddply function"

2006 Mar 07
2
(newbie) Accessing the pieces of a 'by' object
Folks, I know that I can do the following using a loop. That's been a lot easier for me to write and understand. But I am trying to force myself to use more vectorized / matrixed code so that eventually I will become a better R programmer. I have a dataframe that has some values by Year, Quarter and Ranking. The variable of interest is the return (F3MRet), to be weighted averaged within the
2006 Mar 08
0
survival
Dear R-helpers, We marked 6000 leaves from 5 SPECIES - 10 individuals/species - in two different TREATMENTs: a control and a dry-plot from which 50% of incoming precipitation was excluded. We followed those leaves for 42 months and noted the presence and absence at each visit. I then carried out a Cox Harzard model to see differences in leaf mortality between parcels and among species over time:
2014 Nov 13
2
Help with ddply/summarize
I have a straightforward application of ddply() and summarize(): ddply(MyFrame, .(Treatment, Week), summarize, MeanValue=mean(MyVar)) This works just fine: Treatment Week MeanValue 1 MyDrug BASELINE 5.91 2 MyDrug WEEK 1 4.68 3 MyDrug WEEK 2 4.08 4 MyDrug WEEK 3 3.67 5 MyDrug WEEK 4 2.96 6 MyDrug WEEK 5 2.57 7 MyDrug
2012 Apr 03
1
help in ddply
Hi I've records like this df= x panel 4 1 93 2 21 3 83 4 75 1 87 2 87 3 78 4 50 1 76 2 86 3 65 4 84 1 40 2 39 3 26 4 i want to create histogram out of it . i want all the mid and count values for panel wise my code is histoutput = ddply(df,.(df[2]),hist) i'm not able to get the required result. please help me using for loop takes a lot of time if there are more records ----- Thanks
2012 Mar 03
3
Using ddply within a function by argument transfer
An embedded and charset-unspecified text was scrubbed... Name: inte tillg?nglig URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120303/a62e41f2/attachment.pl>
2011 Apr 13
0
ddply and nlminb
Hello I'm new to R (one week) so please excuse any obvious mistakes in my code or posting. I am attempting to fit a non linear function defining the relationship between dependent variable A and the variables PAR and T grouped by the condition Di. The following steps are taken in the Rcode below: 1) load the data (not shown) 2) define the function to be fit 3) define the starting values
2012 May 05
1
Correct use of ddply with own function
Hi, I am really confused how ddply work, so maybe you can help me. I created a function that sorts a vector etc. fn <- function(x){ x1 <- sort(x) x2 <- seq(length(x)) x3 <- x2/max(x2) df <- data.frame(x1,x2,x3) df } Probably this is not the best form of the function, but at least it produces what I want (data to plot a cumulative count curve). This function works on a
2012 Jul 24
1
Function for ddply
Hello, all. I'm new to R and just beginning to learn to write functions. I know I'm out of my depth posting here, and I'm sure my issue is mundane. But here goes. I'm analyzing the American National Election Study (nes), looking at mean values of a numeric dep_var (environ.therm) across values of a factor (partyid3). I use ddply from plyr and wtd.mean from Hmisc. The nes requires a
2010 Apr 07
1
unexpected behaviour with ddply and colwise
Hi, I am confused by results from: > ddply(aa, names(aa), colwise(sum)) I thought ddply was just calling colwise(sum)() with each column. However ddply() returns a 13 x 5 result !! The general result I expected is similar to that of apply() , or using colwise(sum)() alone. Shouldn't ddply() produce the same ? Thanks in advance for your help, - Stuart Andrews >
2013 Jun 10
1
modify and append new rows to a data.frame using ddply
Hi, I have a data.frame that contains a variable act which records the duration (in seconds) of two states (wet-dry) for several individuals (identified by Ring) over a period of time. Since I want to work with daytime (i.e. from sunrise till sunset) and night time (i.e. from sunset till next sunrise), I have to split act from time[i] till sunset and from sunset until time[i+1], and from time[k]
2010 Jun 01
1
data frame manipulation ddply
Dear group, Here is my data frame: futures <- structure(list(DESCRIPTION = c("CORN Jul/10", "CORN Jul/10", "CORN Jul/10", "CORN Jul/10", "CORN Jul/10", "LIVE CATTLE Aug/10", "LIVE CATTLE Aug/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11
2011 May 11
3
ddply with mean and max...
I'm trying to use ddply to compute summary statistics for many variables splitting on the variable site. however, it seems to work fine for mean() but if i use max() or min() things fall apart. whats going on? test.set<-data.frame(site=1:10,x=.Random.seed[1:100],y=rnorm(100)) means<-ddply(test.set,.(site),mean) means site x y 1 1 -97459496 -0.14826303 2
2011 Oct 01
1
error using ddply to generate means
Dear list, I encounter an error when I try to use ddply to generate means as follows: fun3<-structure(list(sector = structure(list(gics_sector_name = c("Financials", "Financials", "Materials", "Materials")), .Names = "gics_sector_name", row.names = structure(c("UBSN VX Equity", "LLOY LN Equity", "AI FP Equity",
2009 Nov 19
1
Performance of 'by' and 'ddply' on a large data frame
I've only recently started using R. One of the problems I come up against is after having extracted a large dataset (>5M rows) out of database, I realize I need another variable. In this case I have data frame with dates. I want to find the minimum date for each value of x1 and add that minimum date to my data.frame. > randomdf <- function(p) { data.frame(x1=sample(1:10^4, 10^p,
2011 Jun 21
4
ddply to count frequency of combinations
I have a dataframe df with two columns x and y. I want to count the number of times a unique x, y combination occurs. For example x<- c(1,2,3,4,5,1,2,3,4) y<- c(1,2,3,4,5,1,2,4,1) df<-as.data.frame(cbind(x, y)) #what is the correct way to use ddply for this example? ddply(df, c('x','y', summarize, ??) #desired output -- format and order doesn't matter # (x, y)
2013 Aug 30
0
ddply for comparing simulation results
This might do it: > lhs=c('a','a','a','b') > rhs=c('a','b','b','b') > > > # function to determine differences > f_diff <- function(l, r){ + t_l <- table(l) + t_r <- table(r) + # compare 'l' to 'r' + sapply(names(t_l), function(x){ + if (is.na(t_r[x])) return(t_l[x])
2010 Feb 03
1
Calculating subsets "on the fly" with ddply
Hi, [I sent this to the plyr mailing list (late) last night, but it seems to be lost in the moderation queue, so here's a shot to the broadeR community] Apologies in advance for being more verbose than necessary, but I'm not even sure how to ask this question in the context of plyr, so ... here goes. As meaningless as this might be to do with the `iris` data, the spirit of it is what
2011 Aug 23
3
ddply - how to transform df column "in place"
Dear R-users, I am trying to get the plyr syntax right, without much success. Given: d<- data.frame(cbind(x=1,y=seq(20100801,20100830,1))) names(d)<-c("first", "daterep") d2<-d # I can convert the daterep column in place the classic way: d$daterep<-as.Date(strptime(d$daterep, format="%Y%m%d")) # How to do it the plyr way? ddply(d2,
2009 Nov 19
1
ddply function nesting problems
While putting my R code into functions, I've encountered a ddply function nesting issue and need a bit of advice on the proper way to fix it.? I've tried several approahces, but neither worked and I need to have the ability to include the "cut", "range", and "fullseq" methods within ddply.? (For a bit of that explanation refer to
2012 Sep 06
1
use of ddply() within function
Dear all, I am encountering problems with the application of ddply within the body of a self-defined function. The script is the following: moncostcarmoto <- function(costtype){ costaux_result <- data.frame() for (purp in PURPcount){for (per in PERcount){ costcarin =