"R Script"
Powerfool
New Altair Community Member
Can any body help with writing R Scripts?
I have RM v.5.3.005 and R v.2.15.2
Tried to use "Execute Script (R)" operator with this code (kernel regression estimator):
x<-input[1]
y<-input[2]
H <- function(z) {
if (abs(z)<=1)
return((cos(pi*z)+1)/2)
else
return(0)
}
ys <- function(t,x,y,cs) {
m <- length(t)
n <- length(x)
K <- c(1)
result <- c(1)
for (i in 1:m)
{
for (j in 1:n)
K <- H((x-t)/cs)
denominator <- sum(K)
if (denominator==0)
result <- 0
else
{
numerator <-0
for (j in 1:n)
{numerator <- numerator + y*K}
result <- numerator/denominator
}
}
return (result)
}
output<-c(x,y,ys(x,x,y,0.5))
I ran process and got nothing as a result. Reading log got this line:
Feb 16, 2013 12:59:07 PM INFO: Execute Script (R): 1: package 'mlr' is not available (for R version 2.15.2)
So i believe that might be the problem
P.S. Executing the same code in RM's R console everything is OK.
I have RM v.5.3.005 and R v.2.15.2
Tried to use "Execute Script (R)" operator with this code (kernel regression estimator):
x<-input[1]
y<-input[2]
H <- function(z) {
if (abs(z)<=1)
return((cos(pi*z)+1)/2)
else
return(0)
}
ys <- function(t,x,y,cs) {
m <- length(t)
n <- length(x)
K <- c(1)
result <- c(1)
for (i in 1:m)
{
for (j in 1:n)
K <- H((x-t)/cs)
denominator <- sum(K)
if (denominator==0)
result <- 0
else
{
numerator <-0
for (j in 1:n)
{numerator <- numerator + y*K}
result <- numerator/denominator
}
}
return (result)
}
output<-c(x,y,ys(x,x,y,0.5))
I ran process and got nothing as a result. Reading log got this line:
Feb 16, 2013 12:59:07 PM INFO: Execute Script (R): 1: package 'mlr' is not available (for R version 2.15.2)
So i believe that might be the problem
P.S. Executing the same code in RM's R console everything is OK.
0
Answers
-
Right, so I've found the solution myself. For those who got the same trouble:
I've read some threads about similar problems and changed my code into this:
x<-Data$a1
y<-Data$a2
H <- function(z) {
if (abs(z)<=1)
return((cos(pi*z)+1)/2)
else
return(0)
}
ys <- function(t,x,y,cs) {
m <- length(t)
n <- length(x)
K <- c(1)
result <- c(1)
for (i in 1:m)
{
for (j in 1:n)
K <- H((x-t)/cs)
denominator <- sum(K)
if (denominator==0)
result <- 0
else
{
numerator <-0
for (j in 1:n)
{numerator <- numerator + y*K}
result <- numerator/denominator
}
}
return (result)
}
output<-data.frame(x,y,ys(x,x,y,0.5))
Good luck and "make love not war"!!! ;D0