尝试在 R 中创建一个 table 来显示每个行业公司股票价格的均值和标准差

Attempting to create a table in R that shows the mean and sd for stock prices of companies in each sector

我有财务数据 (CleanStocks.csv),其中包括行业、公司及其股票价格。我需要找出每个行业有多少家公司,所以我做了 table(CleanStocks$Sector) 这给了我这个:

Consumer Discretionary           Consumer Staples                     Energy 
                    55                         25                          6 
            Financials                Health Care                Industrials 
                    60                         35                         52 
Information Technology                  Materials                Real Estate 
                    39                         20                         27 

现在我需要将上述每个行业的公司 sd(CleanStocks$Price)mean(CleanStock$Price) 也纳入 table 并且真的不知道从哪里开始,看起来很简单但我卡住了

tapply(CleanStocks<span class="math-container">$Price,CleanStocks$</span>Sector,mean)
tapply(CleanStocks<span class="math-container">$Price,CleanStocks$</span>Sector,sd)