Hello,

Try instead


sMean2 <- tapply(parameter[[Pname]], parameter[[Iname]], mean)

Hope this helps,

Rui Barradas
Em 04-03-2014 17:01, Barry King escreveu:
I am reading parameters from an Excel file but am having trouble using them
in tapply.  Here is a mini-version of my problem.
------------------------------------------------------------------------------------------------------------------------------------------------
sorted <- data.frame(c("Single","Single","Double","Double","Double",
"Triple"),
                      c(324.5, 435.3, 568.3, 345.4, 143.5, 563.5))
colnames(sorted) <- c("ITEM","PRICE")

attach(sorted)
sMean <- tapply(PRICE,ITEM,mean)  # works but cannot use column names
directly
                                   # since reading them from an Excel file
into
                                   # a parameter file

Pname <- c("PRICE")
Iname <- c("ITEM")
parameter <- data.frame(Pname,Iname)  # This mimics reading the specific
column names
                                       # from Excel
# Now I want to indirectly reference the PRICE and ITEM columns but this
does
# not work as expected
sMean2 <- tapply(parameter$Pname, parameter$Iname, mean)


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to