我試圖找到每隊平均打擊率原子序數和平均值。我有一個matrix
類似於我有如下:R:在列表中
bat_avg team_name
[1,] "0.5" "Rockies"
[2,] "0" "Astros"
[3,] "0.5" "Rockies"
[4,] "0" "Padres"
[5,] "0" "Padres"
[6,] "0" "Rockies"
[7,] "0" "Mets"
[8,] "0.4" "Red Sox"
[9,] "0" "Yankees"
[10,] "0" "Rockies"
要找到每隊平均軟化平均我試圖矩陣變換成數據幀,試圖通過球隊的名字來彙總數據。我一直在收到我的數據類型是原子的錯誤。我不確定該如何解決這個問題。我是全新的R和編碼,所以感謝您的幫助!
bat_avg <- Batting_average[,26]
team_name <- Batting_average[,100]
Batting_average <- cbind(bat_avg, team_name)
df.Batting_average <- as.data.frame(Batting_average)
aggdata <- aggregate(Batting_average$team_name, by list(Batting_average$bat_avg],
FUN = mean)
下面是我的數據的頂部
structure(c("0.5", "0", "0.5", "0", "0", "0", "Rockies", "Rockies",
"Rockies", "Rockies", "Rockies", "Rockies"), .Dim = c(6L, 2L),n.Dimnames = list(
NULL, c("bat_avg", "team_name")))
我試圖dput()我的數據,但數據的長度,防止我張貼。 –
創建一個最小的例子,然後例如:輸入(頭(數據)) –
我認爲你需要'聚合(Batting_average $ team_name,by = list(Batting_average $ bat_avg),FUN = mean)' –