Displaying 3 results from an estimated 3 matches for "dfret".
Did you mean:
dfree
2006 Mar 07
2
(newbie) Accessing the pieces of a 'by' object
...ecuase of the need to pass
weighted.mean a weights vector. I tried the by() function, but now I
don't know how to coerce the returned object into a matrix so that I
can reshape it.
> fvs_weighted.mean <- function(y) weighted.mean(y$F3MRet, y$IndexWeight, na.rm=T);
> tmp_byRet <- by(dfReturns,
list(dfReturns$Quarter,dfReturns$Year,dfReturns$Ranking),
fvs_weighted.mean);
And various other ways to get the tmp_byRet object into a matrix were
tried, eg. unlist(), a loop like this:
dfRet <- data.frame(tmp_byRet);
for(i in 1:dim(dfRet)[2]){
dfRet[ ,i] <- as.vector(...
2010 Dec 06
3
[plyr] Question regarding ddply: use of .(as.name(varname)) and varname in ddply function
...9L, 1760L), class = "data.frame")
-----------
If some one doesn't want to open github - here is the code
## Doesn't work
# grp -- name of a column of the the data.frame df
# function call is -- getMinMax1( df1 , grp = "var1")
getMinMax1 <-function(df, grp){
dfret <- ddply( df , .(as.name(grp)), ## I am using
as.name(grp), source of error
function(x){
minmax <- c(mix(x[ , 3]), max(x[ ,3]))
return(minmax)
}
)
return(dfret)
}
## Works fine
# grp -- name of a column of the the da...
2006 Mar 08
0
survival
...ecuase of the need to pass
weighted.mean a weights vector. I tried the by() function, but now I
don't know how to coerce the returned object into a matrix so that I
can reshape it.
> fvs_weighted.mean <- function(y) weighted.mean(y$F3MRet,
y$IndexWeight, na.rm=T);
> tmp_byRet <- by(dfReturns,
list(dfReturns$Quarter,dfReturns$Year,dfReturns$Ranking),
fvs_weighted.mean);
And various other ways to get the tmp_byRet object into a matrix were
tried, eg. unlist(), a loop like this:
dfRet <- data.frame(tmp_byRet);
for(i in 1:dim(dfRet)[2]){
dfRet[ ,i] <- as.vector(...