I am currently trying to create a data frame from another data frame one row at a time. I am trying to rename the last row (as soon as it is added to the data frame) to a given value (stored in another list as entry[1]
).
Currently, I am using
a <- rbind(a, choice)
rownames(a)[nrow(a)] <- entry[1]
However, my output for this still has the rows labeled as a numeric list
optOne optTwo Neither
1 0 1 0
2 1 0 0
n 'count''count''count'
as opposed to
optOne optTwo Neither
cac1001 0 1 0
f253 1 0 1
'name' 'count' 'count' 'count'
I considered saving the name column as part of the actual data in its own column, but this was untenable because I need to be able to perform arithmetic on the actual data in my dataframe
EDIT: Current output for rbind(a, choice) and relevant entryList[1] for the first 10 entries (I will list entryList[1]
as an additional column):
optOne optTwo Neither entryList[1]
1 1 0 0 cac1002
2 1 0 0 cac101
3 1 0 0 cac102
4 1 0 0 cac1101
5 1 0 0 cac1102
6 1 0 0 cac201
7 1 0 0 cac202
8 0 1 0 cac301
9 0 0 1 cac302
10 1 0 0 cac402
EDIT2: One thing that seems rather odd: parts of my code later on that rely on an if loop
if(entry[1] %in% rownames(a)) {
and they work correctly as if entry[1]
was being added to rownames properly