similar to: strange dlply behavior

Displaying 20 results from an estimated 10000 matches similar to: "strange dlply behavior"

2012 Mar 18
1
Help with dlply, loop and column names
Hi, I have a dataframe basically like this: > head(asturias.gen2011[,c(1,4,9:14)]) municipio total upyd psoe pp iu fac tipo 440 Allande 2031 1.44 31.10 39.75 4.01 21.62 1000-10000 443 Aller 12582 1.37 33.30 37.09 15.53 10.35 10000-50000 567 Amieva 805 1.48 32.69 37.36 6.15 20.16 <1000 849
2013 Jan 08
2
plot residuals per factor
Dear R-users, I want to plot residuals vs fitted for multiple groups with ggplot2. I try this code, but unsuccessful. library("plyr") models<-dlply(dat1,"d",function(df) mod<-lm(y~x,data=df) ggplot(models,aes(.fitted,.resid), color=factor(d))+ geom_hline(yintercept=0,col="white",size=2)+ geom_point()+ geom_smooth(se=F) -- --- Catalin-Constantin ROIBU
2011 Mar 11
1
Generation of random numbers in a function - (Return command)
Dear R helpers I have following data.frame and for each product_name, I have associated mean and standard deviation. I need to generate 1000 random no.s for each of these products and find the respective mean and standard deviation.   My R code is as follows.   library(plyr) library(reshape2)   filtered_new <- data.frame(product_name = c("P1", "P2", "P3",
2012 Aug 28
1
don't print object attributes
Dear all Suppose the object below: > require(Hmisc) > require(plyr) > x <- dlply(iris, .(Species), describe) How can I print the object without displaying the attributes? I inspected ?print and ?print.default with no luck. > x $setosa x[, "Sepal.Length"] n missing unique Mean .05 .10 .25 .50 .75 50 0 15 5.006 4.40 4.59
2013 Aug 27
1
[plyr] Moving average filter with plyr
Dear all, I'm stuck with a problem using plyr to process a rather large junk of data. What I'm trying to do is applying a moving average to all the subparts of the dataframe (the example data can be found here https://dl.dropboxusercontent.com/u/2414056/testData.Rdata). require(plyr) load("testData.Rdata") applyfilter<-function(x){ return(filter(x,rep(1/5, times=5))) }
2012 Sep 26
1
Change in order of names after applying "plyr" package
Dear R helpers I have following two data.frames viz. equity_data and param. equity_data = data.frame(security_id = c("Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "AB", "AB", "AB", "AB",
2012 Sep 12
6
How to append the random no.s for different variables in the same data.frame
Dear R helpers, (At the outset I sincerely apologize if I have not put forward my following query properly, though I have tried to do so.) Following is a curtailed part of my R - code where I am trying to generate say 100 random no.s for each of the products under consideration. library(plyr) n = 100 my_code = function(product, output_avg, output_stdev)     { BUR_mc = rnorm(n, output_avg,
2011 Sep 28
2
apply lm function to dataset split by two variables
Dear all, I am not fluent in R and am struggling to 1) apply a lm to a weight-size dataset, thus the model has to run separately for each species, each year; 2) extract coefs, r-squared, n, etc. The data look like this: year sps cm w 2009 50 16 22 2009 50 17 42 2009 50 18 45 2009 51 15 45 2009 51 16 53 2009 51 17 73 2010 50 15 22 2010 50 16 41 2010 50 16 21 2010
2012 Jan 12
1
parallel computation in plyr 1.7
Dear all, I have a question regarding the possibility of parallel computation in plyr version 1.7. The help files of the following functions mention the argument '.parallel': ddply, aaply, llply, daply, adply, dlply, alply, ldply, laply However, the help files of the following functions do not mention this argument: ?d_ply, ?aply, ?lply Is it because parallel computation is not
2009 Mar 04
3
Bug in by() with dates as levels?
Trying to use dates in their R-native form (e.g., POSIXct) rather than turning them into character strings, I've encountered the following problem. I create a data frame where one column is dates. Then I use "by()" to do a calculation on grouped subsets of the data. When I try to extract values from the result, I get "subscript out of bounds". The example below shows the
2010 Nov 25
1
Help on running regression by grouping firms
Hi there, I have a huge data set with multiple firms years and other firm characteristics. I want to run a regression on the dependent variable and other explanatory variables and calculate the residual terms by grouping the firms in same year and same industry. What I want to do is to divide my obseravtion into sub sample that contains the observation with same fiscal year(FYEAR=1990) and same
2008 Sep 30
0
New package: plyr
plyr is a set of tools that solves a common set of problems: you need to break a big problem down into manageable pieces, operate on each pieces and then put all the pieces back together. It's already possible to do this with split and the apply functions, but plyr just makes it all a bit easier with: * consistent names, arguments and outputs * input from and output to data.frames,
2008 Sep 30
0
New package: plyr
plyr is a set of tools that solves a common set of problems: you need to break a big problem down into manageable pieces, operate on each pieces and then put all the pieces back together. It's already possible to do this with split and the apply functions, but plyr just makes it all a bit easier with: * consistent names, arguments and outputs * input from and output to data.frames,
2011 Oct 25
1
regression using GMM for mulltiple groups
Inthe code below I was trying to to obtain the GMM estimates for CAPM (REGRESSION) for 36 stocks each have 180 observations,however it only gives me one output rather than 36. In SAS i would just put in a *By statement*. I have a variable TICKER that categorize them into 36 groups. *How can I obtain all 36 output instead of just one.* **
2010 Aug 09
2
coef(summary) and plyr
Dear all, I?m having trouble getting a list of regression variables back into a dataframe. mydf <- data.frame(x1=rnorm(100), x2=rnorm(100), x3=rnorm(100)) mydf$fac<-factor(sample((0:2),replace=T,100)) mydf$y<- mydf$x1+0.01+mydf$x2*3-mydf$x3*19+rnorm(100) dlply(mydf,.(fac),function(df) lm(y~x1+x2+x3,data=df))->dl here I?d like to use ldply(dl,coef(summary)) or something
2013 Oct 12
2
Order of factors with facets in ggplot2
Hello, I'd like to produce a ggplot where the order of factors within facets is based on the average of another variable. Here's a reproducible example. My problem is that the factors are ordered similarly in both facets. I would like to have, within each facet of `f1', boxplots for 'x' within each factor `f2', where the boxplots are ordered based on the average of x
2009 Sep 28
4
Running an ANOVA with a BY
I have a simple 1 way anova coded like summary(ANOVA1way <- aov(Value ~ WellID, data = welldata)) How can I use the BY function to do this ANOVA for each group using another variable in the dataset?? I tried coding it like this, but it doesn't seem to work. summary(ANOVA1way <- by(welldata, Analyte, function(x) aov(Value ~ WellID, data = welldata))) In SAS I would code it like this:
2011 Feb 08
1
Grouping by factors in R
I'm having a hard time figuring out how to group results by certain factors in R. I have data with the following headings: [1] "Time" "Plot" "LatCat" "Elevation" "ElevCat" "Aspect" "AspCat" "Slope" [9] "SlopeCat" "Species" "SizeClass" "Stems" and
2008 Oct 03
1
question on xyplot
Hi List, I have the following problem: I am using the multilevel package and make.univ function for available in the package and then xyplot from lattice and I want to know how could I be able to use the ?coefficient? for the straight line that passes the data ? Example from help: library(multilevel) data(univbct) #a data set already in univariate or stacked form for job satisfaction
2008 Oct 02
0
[solutions] "tapply versus by" in function with more than 1 arguments
Thanks to all. I summarized (in order to thank the list) the solutions to help future workers searching subjects like this at R help.   # Number of rows nr = 10 # Data set dataf = as.data.frame(matrix(c(rnorm(nr),rnorm(nr)*2,runif(nr),sort(c(1,1,2,2,3,3,sample(1:3,nr-6,replace=TRUE)))),ncol=4)) names(dataf)[4] = "class" #----------------------------------------------------- #Solution 1: