Discussion:
[julia-users] How can I change the R code to Julia code. Thank you.
m***@163.com
2015-07-31 04:44:30 UTC
Permalink
Hello, I do not know how to change "list()" "c(sib1,sib2)" and
"a[[v]][inhe[[v]]==par] <-
par.al[[par]][inhe[[v]]==par]" in R to julia code.
It is error:
ERROR: BoundsError()
in getindex at array.jl:246 (repeats 2 times)

#####R code
n.ped <- nrow(sib1$pat)
n.mark <- ncol(sib1$pat)
n.al <- length(f)
par.al <- list()
for(par in 1:4) par.al[[par]] <-
matrix(sample(1:n.al,n.ped*n.mark,
replace=TRUE,prob=f),n.ped,n.mark)
a <- inhe <- c(sib1,sib2)
for (v in 1:4) for (par in 1:4)
a[[v]][inhe[[v]]==par] <-
par.al[[par]][inhe[[v]]==par]


###julia code
nped=size(sib1,1)
nmark=size(sib1,2)
nal=size(f,2)
paral=Dict()
for (par=1:4)
paral[[par]]=reshape(wsample([1:nal],vec(f),nped*4*nmark),nped*4,nmark)
end
#a=inhe=hcat(sib1,sib2,sib3,sib4)
a=inhe=(Sib1,Sib2,Sib3,Sib4)
a=inhe=convert(DataFrame,a)
println("mbjok")
for (v=1:4) for(par=1:4)
println(v,par)
if inhe[[v]]==par
a[v,inhe[v]]=paral[par,inhe[v]]
end
end end
Nils Gudat
2015-07-31 12:36:57 UTC
Permalink
As your code is not a reproducible example, there's no way to say what's
going wrong exactly. The error message is telling you that you are trying
to access an array out of bounds, so it would be necessary to know the
sizes of the arrays in your code to find the error.

Two other things:
- Julia is case-sensitive, so it might be problematic to refer to "sib1" in
the first line and "Sib1" in line 9.
- nested loops can concisely by written as: "for v=1:4, par=1:4 [code
block] end" (see
http://julia.readthedocs.org/en/latest/manual/control-flow/#repeated-evaluation-loops)
Loading...