I'm doing some small calculations and i decided to fill the data inside a data.table
since it's much faster than data.frame
and rbind
so basically my code is something like that:
df
is a data.frame
used in the calculation but it's important what does it contain.
l=12000
dti = 1
dt = data.table(ni = 0, nj = 0, regerr = 0)
for (i in seq(1,12000,200)) {
for (j in seq(1, 12000, 200)) {
for (ind in 1:nrow(df)) {
if( i+j >= l/2 ){
df[ind,]$X = df[ind,]$pos * 2
} else {
df[ind,]$X = df[ind,]$pos/l
}
}
for (i in 1:100) { # 100 sample
sample(df$X,nrow(df), replace=FALSE)
fit=lm(X ~ gx, df) #linear regression calculation
regerror=sum(residuals(fit)^2)
print(paste(i,j,regerror))
set(dt,dti,1L,as.double(i))
set(dt,dti,2L,as.double(j))
set(dt,dti,3L,regerror)
dti=dti+1
}
}
}
The code prints the first few rounds of print(paste(i,j,regerror))
and then it quits with this error:
*** caught segfault ***
address 0x3ff00008, cause 'memory not mapped'
Segmentation fault (core dumped)
EDIT
structure(list(ax = c(-0.0242214, 0.19770304, 0.01587302, -0.0374415,
0.05079826, 0.12209738), gx = c(-0.3913043, -0.0242214, -0.4259067,
-0.725, -0.0374415, 0.01587302), pos = c(11222, 13564, 16532,
12543, 12534, 14354)), .Names = c("ax", "gx", "pos"), row.names = c(NA,
-6L), class = "data.frame")
Any ideas are appreciated.