I have an R data frame with factor columns.
dataframe <- read.csv("import.csv")
dataframe$col1 = as.factor(dataframe$col1)
dataframe$col2 = as.factor(dataframe$col2)
...
How can I generate a new row from labels?
newRow = dataframe[1,] #template
newRow[1] = ?
newRow[2] = ?
Lets say col1 includes "TestValue". I would like to set newRow[1] value to "TestValue" as if it was selected from my dataframe. How can I do that?
I know I can get factor index like so:
match(c("TestValue"),levels(dataframe$col1))
[1] 3
But whenever I assign anything to newRow[1], I seem to change its type.
Thanks in advance.