I have a data frame that I want to build up programmatically. I have some of the columns in advance, but not all, and I'd like to add them as they come up. So for example:
d <- data.frame("Test" = 0)
gives me this:
Test
1 0
And the following:
d <- cbind( "Sun" = 0,d)
works as expected:
Sun Test
1 0 0
But this:
for ( i in daynames) {
d <- cbind(i = 0 ,d)
}
Yields this:
i i i i i i i Test
1 Sat Fri Thu Wed Tue Mon Sun 0
Rather than this:
Sun Mon Tue Wed Thu Fri Sat Test
1 0 0 0 0 0 0 0 0
How can I bind the columns to the data frame with the value of i rather than the identifier itself? Is there some way to do this that is more R-like?