Is there a way to do it?
I’m stuck with this:
m <- 10 # nof row
n <- 5 # nof column
# We will fill each cell with '0'
all <-c()
for (i in 1:m) {
row_i <- c(rep(0,n))
all <- c(all,row_i)
}
Which only create 1 row as output.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Why not use a matrix?
data.framesare for storing columns of varying types.So,
If you really want a
data.frame, coerce to one – the column names will simply be a default:The problem with your approach is that you simply append the values one after the other, ignoring the dimensions you want. You can do it like this, but it’s not a good idea to grow data, better to allocate it all upfront as above. Also, this results in a matrix anyway, which I think is what you should use.
WARNING: bad code ahead!