0

i'm new to R and below is my code but i cant knit the file to html because it says object of type 'closure' is not subsettable, how should I change my code?

mean(data$salary)
[1] 865.8644

how to change my code to let it works?

Phil
  • 7,287
  • 3
  • 36
  • 66
james
  • 17
  • 1
  • Does this answer your question? [Error in : object of type 'closure' is not subsettable](https://stackoverflow.com/a/11308796/5221626) – Phil Oct 31 '22 at 05:43
  • We need a reproducible example if possible. You are probably failing to define `data` *within your Rmarkdown file*; knitting uses a new, clean environment so it won't see variables that you have only defined in your global workspace. – Ben Bolker Oct 31 '22 at 13:09

1 Answers1

0

Check you code upstream, you're probably reassigning data to something else.

When you knit a document, R executes everything sequentially, it might be the case that you're doing something like this.

data <- actual_dataframe
...
couple lines below
...
data <- 1
...
# then you hit your error
mean(data$salary)
Kean Rawr
  • 33
  • 1
  • 6
  • Hi, I didn't add anything upstream, i have a table called data which include salary information, so i use mean(data$salary) to find the mean, but occur with this error – james Oct 31 '22 at 03:21
  • I think this might be backwards. OP is probably *failing* to assign a value to `data`, so the `data` function from base R is being found instead. The code you've posted throws a different error ("$ operator is invalid for atomic vectors") – Ben Bolker Oct 31 '22 at 13:08