I would like to modify this line:
`with(EquityFundamentals, median(EquityFundamentals$Forward.P.E[EquityFundamentals$Industry == "Entertainment"], na.rm = "TRUE"))`
- to use a list of names, not just "Entertainment"
- The list of names is characters in a vector called "Sectors"
- The output would be:
- new values for every sector (e.g. a median for every sector; MedianEnergy, MedianTech, etc.) OR
- a data frame with the Sector in column 1 and Median in column 2
Data:
> EquityFundamentals
Sector.Title. Forward_P.E.Title.
1 Energy 6.7
2 Energy 7.5
3 Tech 10.4
4 Tech 11.5
structure(list(
Sector.Title. = structure(c(1L,1L,2L,2L),
.Label = c("Energy","Tech"), class = "factor"),
Forward_P.E.Title. = c(6.7,7.5,10.4,11.5)),
.Names = c("Sector.Title.", "Forward_P.E.Title."
), class = "data.frame", row.names = c(NA, -4L))