Having trouble. What I have is:
dec_amt <- function(x, k) format(round(x, k), nsmall=k) # Formatting decimal places
example.df <- data.frame(replicate(8,sample(0:100000,1000,rep=TRUE)))
names(example.df) <- c("AF", "CD", "CS", "ED", "LP", "PI", "RR", "TD")
probTab_test2 <- function(x = c(...), y=c(...), z=c(...))
{
m.TABLE <- list()
EXP <- list()
PROB <- c(seq(.10, .90, .10), seq(.91,.99,.01), seq(.995, .999, .001))
PERIOD <- dec_amt(1/(1-PROB), 2)
for (i in 1:(length(z))) {
if (length(z) == 1)
{
break
}
EXP <- quantile(example.df[,z[i]], PROB)
EXP <- formatC(EXP, format='d', big.mark=',')
m.TABLE <- list(data.frame(PERIOD, EXP))
print(m.TABLE)
}
EXP <- quantile(example.df[,z], PROB)
EXP <- formatC(EXP, format='d', big.mark=',')
TABLE <- data.frame(PERIOD, EXP)
return(TABLE)
}
probTab_test2(c("Consumer Products"), c("All Revenues"),c("TD", "LP"))
Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) :
undefined columns selected
What I want is, if the length of the argument z is > 1 then for every element of z, I want it to create an 'EXP' column that I can bind into a dataframe (defined as m.TABLE) so at the end I would have a list of 'z' number of dataframes.
I feel like the quantile function is not happy about me passing through a dataframe instead of a vector, but not sure how to get around that in this loop. Suggestions would be great, happy to provide further information.
Note - feel free to disregard my x, y arguments - those will be used to call an outside function, but not noteworthy for this issue.
quantile()is not for dataframes.library("fortunes"); fortune(85)quantile()? Right now, I'm just grabbing it as a dataframe.