23
loading...
This website collects cookies to deliver better user experience
data.frame
or vector
.mean[1]
## Error in mean[1] : object of type 'closure' is not subsettable
mean[[1]]
## Error in mean[[1]] : object of type 'closure' is not subsettable
mean$a
## Error in mean$a : object of type 'closure' is not subsettable
shiny
, the most likely cause is that you’re trying to work with a reactive
expression without calling it as a function using parentheses.library(shiny)
reactive_df <- reactive({
data.frame(col1 = c(1,2,3),
col2 = c(4,5,6))
})
isolate({
print(reactive_df())
print(reactive_df()$col1)
})
col1 col2
1 1 4
2 2 5
3 3 6
[1] 1 2 3
isolate(
reactive_df$col1
)
Error in reactive_df$col1 : object of type 'closure' is not subsettable
`+`[1]
## Error in `+`[1] : object of type 'builtin' is not subsettable
`if`[1]
## Error in `if`[1] : object of type 'special' is not subsettable
+
is an operator and if
is a special type in R, you cannot subset operator and reserved keywords.profit
is a function, and you are calling profit[i]
.nsims=1000
sim.demand=rep(NA,nsims)
for(i in 1:nsims){
sim.demand[i]=rnorm(12, 12000, sd=3496.752)
}
profit <- function(n)
for(i in 1:1000){
if(sim.demand[i]<=n)
profit[i]=-100000-(80*n)+100*sim.demand[i]+30*(n-sim.demand[i]) else
profit[i]=-100000-(80*n)+100*n
}
# Output
Error in profit[i] = -1e+05 - (80 * n) + 100 * n :
object of type 'closure' is not subsettable
return_profit
) and return the variable at the end of the function as shown below.nsims=1000
sim.demand=rep(NA,nsims)
for(i in 1:nsims){
sim.demand[i]=rnorm(12, 12000, sd=3496.752)
}
profit <- function(n){
return_profit<-rep(NA, 1000)
for(i in 1:1000){
if(sim.demand[i]<=n) {
return_profit[i]=-100000-(80*n)+100*sim.demand[i]+30*(n-sim.demand[i])
}
else{
return_profit[i]=-100000-(80*n)+100*n
}
}
return_profit
}