R 如何在矩阵中找到特定给定值的行和列?
我有NBA 10名球员的得分和比赛数据 我想知道从2005年到2014年,谁的每场比赛得分最高,并编写了以下代码: 为了找到每个玩家的PPG,我编写了以下内容:R 如何在矩阵中找到特定给定值的行和列?,r,matrix,rows,R,Matrix,Rows,我有NBA 10名球员的得分和比赛数据 我想知道从2005年到2014年,谁的每场比赛得分最高,并编写了以下代码: 为了找到每个玩家的PPG,我编写了以下内容: Points P<-round(Points/Games,2) P 积分 P欢迎使用堆栈溢出。下次尝试包含示例数据。它帮助我们帮助你。Her是一个使用dplyr包的解决方案。它是R方言tidyverse的一部分。如果您只是在学习R,请安装Tidyverse软件包套件。它将是你最好的朋友 data <- data.frame
Points
P<-round(Points/Games,2)
P
积分
P欢迎使用堆栈溢出。下次尝试包含示例数据。它帮助我们帮助你。Her是一个使用
dplyr
包的解决方案。它是R
方言tidyverse
的一部分。如果您只是在学习R
,请安装Tidyverse软件包套件。它将是你最好的朋友
data <- data.frame(points = c(10, 12, 12, 4),
games = c(2, 3, 2, 1),
dude = c("a", "b", "c", "d"))
library(dplyr)
theDude <- data %>% #start with the data above and pipe it to the next line
mutate(pointsPerGame = points/games) %>% # create the average variable and pipe to next line
filter(pointsPerGame == max(pointsPerGame)) %>% # keep only the record(s) with the largest average and pipe to the next line
select(dude) # keep the person's name
data%#创建平均变量并将其输送到下一行
过滤器(pointsPerGame==max(pointsPerGame))%>%#仅保留平均值最大的记录并将其输送到下一行
选择(都德)#保留此人的姓名
欢迎来到堆栈溢出。下次尝试包含示例数据。它帮助我们帮助你。Her是一个使用dplyr
包的解决方案。它是R
方言tidyverse
的一部分。如果您只是在学习R
,请安装Tidyverse软件包套件。它将是你最好的朋友
data <- data.frame(points = c(10, 12, 12, 4),
games = c(2, 3, 2, 1),
dude = c("a", "b", "c", "d"))
library(dplyr)
theDude <- data %>% #start with the data above and pipe it to the next line
mutate(pointsPerGame = points/games) %>% # create the average variable and pipe to next line
filter(pointsPerGame == max(pointsPerGame)) %>% # keep only the record(s) with the largest average and pipe to the next line
select(dude) # keep the person's name
data%#创建平均变量并将其输送到下一行
过滤器(pointsPerGame==max(pointsPerGame))%>%#仅保留平均值最大的记录并将其输送到下一行
选择(都德)#保留此人的姓名
也许您可以使用选项arr.ind=TRUE
which(P == max(P),arr.ind = TRUE)
也许您可以尝试使用选项arr.ind=TRUE
which(P == max(P),arr.ind = TRUE)