So I am using this code below. maindata
is a table of players, their home towns, and their points per game. I am trying to make a new table that has the cities in one column, and the average points per game in the second (as shown in table A). I keep getting a table with the cities listed and the rows for AvgPoints
all showing NA. I get this error "argument is not numeric or logical: returning NAargument is not numeric or logical", and it repeats itself hundreds of times. Main data has 3561 observations.
point <- maindata%>%
group_by(City, State) %>%
summarise(AvgPoints = mean(PTS.1, na.rm = TRUE))
Table A
City AvgPoints
----------------------------
New York City 19.9
Los Angeles 22.1
Boston 13.3
str(maindata)
for the type of columns. or specificallyclass(maindata$PTS.1)
May be the 'PTS.1' is not numeric – akruncharacter
. In the new version of R, it should becharacter
class instead offactor
becausestringsAsFactors = FALSE
by default. My point is that if your column havec(1.5, 1.2, 'a1')
, it is not a numeric column because one of the element is not numeric. you can convert to numeric from factor withmaindata %>% mutate(PTS.1 = as.numeric(as.character(PTS.1)))
and then do the group by. There would be some friendly warning while converting the non-numeric to NA – akrun