I was wondering how I could have d
in my R code below be used in legend
?
Note that the reason I don't use d = c("dnorm", "dcauchy")
is that in my actual code I need to use d[[1]](0)
which doesn't work with quotations.
plot(1)
d = c(dnorm, dcauchy)
legend("topleft", legend = d) ## HERE how can I have the two terms:
## dnorm and dcauchy in `d` appear as legend?
If you wish to use the same list as both the names and the functions you can do this.
d = c("dnorm", "dcauchy") # works for printing strings
And when you want to use it as a function write
get(d[[1]])(0)
[1] 0.3989423
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.