excel - How to pass value from VBA variable to R in RExcel macro -
i new writing rexcel macros, , have question. taking user input macro through inputbox()
. input integer. want pass integer value r.
this attempt:
option explicit sub kmeansclustering() dim k integer rinterface.putdataframe "mydata", selection rinterface.rrun "testdata <- na.omit(mydata)" rinterface.rrun "testdata <- scale(testdata)" k = inputbox("enter k") ' supply data vba k variable k r variable rinterface.rrun "fit <- kmeans(testdata, k)" rinterface.rrun "aggregate(testdata,by=list(fit$cluster),fun=mean)" rinterface.rrun "result <- data.frame(testdata, fit$cluster)" end sub
before using "k" in r must first transfer value r variable (array):
rinterface.putarrayfromvba("k_value", k) rinterface.rrun "fit <- kmeans(testdata, k_value)"
Comments
Post a Comment