search for: dlply

Displaying 20 results from an estimated 48 matches for "dlply".

Did you mean: ddply
2009 Jul 21
1
strange dlply behavior
I'm running R 2.9.1 on winXP, using the library plyr. Can anyone explain to me what is going wrong in this code? (in particular see lines marked with ******************) Trying to modify objects in a list created using dlply seems to corrupt the objects in the list. > library(plyr) > d=as.data.frame(cbind(c(1,1,1,2,2,2),c(1,2,3,4,5,6))) > d V1 V2 1 1 1 2 1 2 3 1 3 4 2 4 5 2 5 6 2 6 > c=dlply(d,.(V1)) > c [[1]] V1 V2 1 1 1 2 1 2 3 1 3 [[2]] V1 V2 4 2 4 5 2 5 6 2 6 ## displ...
2012 Mar 18
1
Help with dlply, loop and column names
...94 0.98 34.28 26.87 23.30 10.98 1000-10000 I want to do the following: 1. for every party (psoe, pp, etc.) I want to create a variable like this: upyd.lm.tipos, psoe.lm.tipos, etc. 2. I want to store in this variable a regression (psoe~total), but split up by tipo. I have the main idea of using dlply from the plyr vignette. But when I try to put all this in a loop I'm coming into trouble and I'm at the moment really confused how to solve this problem: I have the following function: elecregtipos <- function(y){ z<-dlply(asturias.gen2011, .(tipo), function(x) lm(x[,y]~x$edad.m...
2011 Mar 11
1
Generation of random numbers in a function - (Return command)
...<- 100 myfunction_mc = function(product_name, output_avg, output_stdev) { product_usage_borrowing_room_mc = rnorm(n, output_avg, output_stdev) output_avg_mc = mean(product_usage_borrowing_room_mc) output_stdev_mc = sd(product_usage_borrowing_room_mc) return(output_avg_mc ) } result <- dlply(.data = filtered_new, .variables = "product_name", .fun = function(x)                  myfunction_mc(product_name = x$product_name, output_avg = x$output_avg,                  output_stdev = x$output_stdev)) result1 <- data.frame(result) result2 <- melt(result1) result <- da...
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 Forestry engineer, PhD Forestry Faculty of Suceava Str. Univ...
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 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
2012 Sep 12
6
How to append the random no.s for different variables in the same data.frame
...y(plyr) n = 100 my_code = function(product, output_avg, output_stdev)     { BUR_mc = rnorm(n, output_avg, output_stdev) sim_BUR = data.frame(product, BUR_mc) write.csv(data.frame(sim_BUR), 'sim_BUR.csv', row.names = FALSE)   return(list(output_avg, output_stdev))     } result <- dlply(.data = My_data, .variables = "product", .fun = function(x)                  my_code(product = x$product, output_avg = x$output_avg,                  output_stdev = x$output_stdev)) There are some 12 products (and this may vary each time). In my original code, the "return" sta...
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))) }
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 similar but I cant figure it out... Best, M
2011 Jun 03
0
ragged data.frame? using plyr
...tapply(score_out.melt$score,INDEX=score_out.melt$id,mean) tblscore_iqr<-tapply(score_out.melt$score,INDEX=score_out.melt$id,IQR) score_mean_iqr<-data.frame(id=names(tblscore_iqr),mean=tblscore_mean,iqr=tblscore_iqr) However, as it turns out, my data look more like: dat<-dat[-sam] ldply(dlply(dat,.(id,day),adj.values),length) So on different days I only have data for some of the id variables which leads to a "ragged" data.frame. ddply(dat,.(id,day),adj.values) can i do something like ldply(dlply(dat,.(id.day),adj.values), function(x){put in a NA for the places where data i...
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 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...
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
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
2011 Sep 29
3
For loop for subset - repeating same over and over?
Hello, I am using the following script to run an anova for numerous species in a table that I have: SiteSpp <-
2011 Nov 03
2
Take variables in data.frame and create list of matrices
Hi, I have this sample data below and would like to create a list of matricies. setseed(1254) id <- c(1,1,1,1 ,2,2,2) o <- as.factor(c(1:4, 1, 3, 4)) r <- rep(.5, 7) v <- rnorm(7) s <- rnorm(7) dat <-data.frame(id, o, r, v, s) dat #> dat # id o r v s # 1 1 0.5 0.7024631 2.0813672 # 1 2 0.5 -0.5541955 0.1095156 # 1 3 0.5 -1.0418167 0.4164930 # 1
2012 Mar 30
3
Adding text for written comments to bottom of graphs
Hello All, Recently developed the code below for graphing patterns of chemotherapy administration. As someone just starting to use R in their work, I managed to figure out some parts of the code but needed help with others. setwd("N:/Regimen Coding/0906/Plots Test") getwd() TestData <- structure(list(profile_key = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3), line = c(1, 1,
2012 Sep 26
1
Change in order of names after applying "plyr" package
...        return_mean = mean(security_rate_returns)         return_sd = sd(security_rate_returns)         simulation = rnorm(n, return_mean, return_sd)         qq = sort(simulation, decreasing = TRUE)         VaR_mc = -qq[alpha * n]*sqrt(t)         return(VaR_mc)     }      result_method_other <- dlply(.data = equity_data, .variables = "security_id", .fun = function(x)                       mc_VaR(ason_date = x$ason_date, security_id = x$security_id,                       security_rate = x$security_rate))      > result_method_other $AB [1] 0.2657424 $AD [1] 0.212061 $Air [1] 6....
2011 Aug 29
2
splitting into multiple dataframes and then create a loop to work
Dear All Sorry for this simple question, I could not solve it by spending days. My data looks like this: # data set.seed(1234) clvar <- c( rep(1, 10), rep(2, 10), rep(3, 10), rep(4, 10)) # I have 100 level for this factor var; yvar <- rnorm(40, 10,6); var1 <- rnorm(40, 10,4); var2 <- rnorm(40, 10,4); var3 <- rnorm(40, 5, 2); var4 <- rnorm(40, 10, 3); var5 <- rnorm(40, 15,
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: