I am calculating a table for each row of a data.frame df
.
I would like to assign these tables as values of a new column of my database (so that each row has one table assigned).
But trying to put a table into a data.frame only results in using the first value of the table.
df <- data.frame(values = c("row 1","row 2", "row 3"))
v_row_1 <- c("one", "one", "two", "three", "three")
t_row_1 <- table(v_row_1)
df[1, "tables"] <- t_row_1
Warning message:
In `[<-.data.frame`(`*tmp*`, 1, value = list(values = c(1, 2, 3), :
provided 2 variables to replace 1 variables
I think that one solution would be to convert my table t
into a string object and then assing this object to the cell in my dataframe. But if I use paste(toString(t))
to do this I lose the table names (and I still can't get this thing into a data.frame cell).
My desidered output would roughtly look like:
values tables
row 1 one 2 three 2 two 1
row 2 ...
row 3 ...
I do not mind if the tables are converted in a linear string as long as they are readable.