Tibble seems to be messing up the variable type whenever I call it a certain way. Here's a working example:
a = rep(LETTERS[1:10], times=5)
b = 1:10
d = data.frame(a,b)
d = d%>%group_by(a)%>%summarize(total=sum(b))
mean(d[,"total"])
Strangely, it does work when I do
mean(d$total)
or when I do
mean(d[["total"]])
Unfortunately, I have to call the variable using mean(d[,"total"])
; I can't use d$total
because I'm passing the variable name within a function, and I can't use d[['total']]
because that will not work for data frames.
Any ideas why this is happening and how I can fix it?