Good night dear!
For years I have a problem that I have avoided with the use of the switch
function, but now I want to solve by following the good practices of object
orientation (OOP).
My function was created to generate experiments according to some input
parameters. Therefore, the first argument
Depends on how you want to specify variables. You are not clear (to me) on
this. But, for instance:
demo <- function(form,df)
{
av <- all.vars(form)
df[,av]
}
demo(~a+b, df)
demo(a~b,df)
?all.vars, ?all.names for details
Bert Gunter
On Wed, May 29, 2019 at 7:33 PM Sorkin, John
wrote:
Bert,
Thank you for your reply. You are correct that your code will print the
contents of the data frame. While it works, it is not as elegant as the lm
function. One does not have to pass the independent and dependent variables to
lm In parentheses.
Fit1<-lm(y~x,data=mydata)
None of the param
Basically, huh?
> df <- data.frame(a = 1:3, b = letters[1:3])
> nm <- names(df)
> print(df[,nm[1]])
[1] 1 2 3
> print(df[,nm[2]])
[1] a b c
Levels: a b c
This can be done within a function, of course:
> demo <- function(df, colnames){
+print(df[,colnames])
+ }
> demo(df,c("a","b"))
a b
1 1
Thanks to several kind people, I understand how to use
deparse(substitute(paramter)) to get as text strings the arguments passed to an
R function. What I still can't do is put the text strings recovered by
deparse(substitute(parameter)) back together to get the columns of a dataframe
passed to
Hello
#RStudio Version 1.2.1335
sessionInfo()
# R version 3.6.0 Patched (2019-05-19 r76539)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 17134)
I am all over the google map with this so far but have made progress.
#https://www.r-graph-gallery.com/stacked-ba
Hello,
This is because you have non-integer values in vector x?
This one works.
##Poisson distribution
f2p <- fitdist(floor(x), "pois")
plot(f2p)
summary(f2p)
Not so well
##negative binomial distribution
f2n <- fitdist(floor(x), "nbinom")
f2n <- fitdist(ceiling(x), "nbinom")
f2n <- fitdist(
Dear R-Experts,
Here is a toy example, reproducible example, I get error messages. I have tried
to fix it by myself using "google is my friend", but I did not get it. If
somebody can help me to fix these errors, would be highly appreciated.
##
install.packages("fitdistrp
8 matches
Mail list logo