我想创建一个函数correlateHeightSpeed(),它会从一个数据列表中生成一个 Dataframe height_Speed。然后它会显示每种类型的过山车和过山车的每种材料的平均高度、平均速度以及高度和速度的相关系数。
主表的示例dput数据如下所示
dput(coaster_Data[1:10, c("name", "material_type", "seating_type","speed","height")])
structure(list(name = c("Goudurix", "Dream catcher", "Alucinakis",
"Anaconda", "Azteka", "Bat Coaster", "Batman : Arkham Asylum",
"Big Thunder Mountain", "EqWalizer", "Calamity Mine"), material_type = structure(c(1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L), levels = c("Steel", "Wooden",
"Hybrid", "na"), class = "factor"), seating_type = c("Sit Down",
"Suspended", "Sit Down", "Sit Down", "Sit Down", "Inverted",
"Inverted", "Sit Down", "Sit Down", "Sit Down"), speed = c(75,
45, 30, 85, 55, 70, 80, 60, 76, 48), height = c(37, 25, 8, 35,
17, 20, 32, 22, 36, 14)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
我已经尝试使数据在前10名higgest和我得到的输出正确,但我需要这样做的所有类型的过山车这是混乱的。
subset_coaster <- data.frame(coaster_Data$name,coaster_Data$material_type,coaster_Data$speed)
1条答案
按热度按时间hc2pp10m1#
试试这个
如您所见,您可以在函数"group_by"中调整您考虑的组