[Solved] Convert R code to Rcpp – for loop, vector input, vector output


I opted to code it in Julia

Logic same just put the curly R braces in:

signal = [0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 ]

n_day = zeros(signal)
i = 1
j = 1
for i in 1:length(signal)
if signal[i] == 1
    n_day[i] = 1
    j = 1
    print("i =", i)
while(j<=4)
  # Carry over index position
        n = i + j  # carry over index position
    n_day[n] = 1
    j = j + 1
end
j=1
n=1
end
end

for output:

julia> print(n_day)
[0 1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0]

solved Convert R code to Rcpp – for loop, vector input, vector output