Basic-Excel-R-Toolkit icon indicating copy to clipboard operation
Basic-Excel-R-Toolkit copied to clipboard

Need a little help...

Open bastringue opened this issue 5 years ago • 1 comments

Hello, I am really impressed by the possibilities that Bert seem to offer...congratulations. I would really make a first vba macro using BERT. I have a rather simple R script that makes a fitting like below and I would like to select the data (instead of reading a csv file), and by calling the macro, make the regression...I don't know how to define the R function "f" in VBA, nor how to call the fit function "nls" and print the fitted coefficients in the spreadsheet...would you have please a similar VBA example? Thanks in advance, Pierre.

`f <- function(t, a1,a2) { c=5.0 exp(a1t+a2log(t/c)) } mydata=read.csv("file.csv",sep=";",header=T)

fit<-nls(p~f(t,a1,a2), data=data.frame(mydata), start=list(a1=1.0, a2=1.0)) t <- seq(0,10,) fitted.data <- data.frame(t=t, p=predict(fit, list(t=t))) print(summary(fit))

bastringue avatar Apr 02 '21 19:04 bastringue

Hi Pierre, you don't need to define the function in VBA to use it, you can keep it as a R function. In order to select a range of cells to provide as a dataframe you need to use a special range.to.data.frame function that BERT provides. I have this explained in the last section of my BERT tutorial: https://youtu.be/jyGwOrKTPRY?t=1057

Ljupch0 avatar Apr 12 '21 22:04 Ljupch0