Why are you looping again inside? for(i in seq(from=1, to=10, by=1)){
i will be a straight sequence from 1 to 10 for(j in seq(from=1, to=2, by=1)){
j will only assume either 1 or 2 so:
if i=1
enters the first loop and j=1
the output[1,] <- 1
now j=2
and output[1,] <- 1
if what you want is to repeat the first value, your second assign should be the j value, something like this
output1 <- data.frame(matrix(ncol=1, nrow=10))
colnames(output1) <- "id"
for(i in seq(from=1, to=10, by=2)){
for(j in seq(from=1, to=2, by=1)){
output[i,] <- i
output[i+1,] <- j
print(paste(i))
}
}
There are also better ways to achive your result (if repeating the value is your desired result)
output1 <- data.frame(matrix(ncol=1, nrow=10))
colnames(output1) <- "id"
for(i in seq(from=1, to=10, by=2)){
output[i,] <- i
output[i+1,] <- i+1
print(paste(i))
}
you can also refer to this question Sequence of Repeated Values in R
which will basically tell you you can create a vector of repeated values in a sequence by using the rep()
command in R