Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201977

How to extract columns from a row and save the output as a variable dplyr

$
0
0

I am trying to extract a specific column from a specific row on my excel sheet (df)however when I try to do so I get the message

Error: ... must evaluate to column positions or names, not a list Call rlang::last_error() to see a backtrace.

When I call rlang::last_error() I get

Backtrace: 1. dplyr::select(., FGA, FTA, TOV, MP, TmFga, TmFta, TmTov, TmMin) 9. tidyselect::vars_select(tbl_vars(.data), !!!enquos(...)) 10. tidyselect:::bad_calls(bad, "must evaluate to { singular(.vars) } positions or names, \\n not { first_type }") 11. tidyselect:::glubort(fmt_calls(calls), ..., .envir = .envir) 12. dplyr::select(., FGA, FTA, TOV, MP, TmFga, TmFta, TmTov, TmMin)

At this point, I am lost. What can I do to my code to work?

library(readxl)
Lakers_Overall_Stats <- read_excel("Desktop/Lakers Overall Stats.xlsx")
library(readxl)
Lakers_Record <- read_excel("Desktop/Lakers Record.xlsx")
require(dplyr)
require(ggplot2)

##WinPercentage of the Team after season
mydata <- Lakers_Record %>% select(Pts,Opp,W,L)%>%
  + mutate(wpct=Pts^13.91/(Pts^13.91+Opp^13.91),expwin=round(wpct*(W+L)),diff=W-expwin)
head(mydata)

##Specifiying 
Lakers_Overall_Stats[23,6] <- TmMin
Lakers_Overall_Stats[23,8] <- TmFga
Lakers_Overall_Stats[23,18] <- TmFta
Lakers_Overall_Stats[23,26] <- TmTov

rlang::last_error()

##Usage Percentage
Usgpct <- Lakers_Overall_Stats %>% select(FGA,FTA,TOV,MP,TmFga,TmFta,TmTov,TmMin)%>%
  + mutate(100*(Fga+0.44*Fta+Tov))*TmMin/(TmFga+0.44*TmFta+TmTov)*5(MP)
##head(Usgpct)
##filter(rank(desc(Usgpct))==1)

Also, am I filtering correctly? or should it be written as

Usgpct <- Lakers_Overall_Stats %>% select(FGA,FTA,TOV,MP,TmFga,TmFta,TmTov,TmMin)%>%
  filter(rank(desc(Usgpct))==1)%>%
  mutate(100*(Fga+0.44*Fta+Tov))*TmMin/(TmFga+0.44*TmFta+TmTov)*5(MP)
head(Usgpct)


Viewing all articles
Browse latest Browse all 201977

Trending Articles