I have a small situation in R.
I have a dataframe as below:
age
numCategories 9
signFeatures NA
nullDeviance NA
residualDeviance NA
aic NA
I want to insert a vector as c(1,2,3) in a particular cell of the data frame.
For example my data frame after replacement should look somethinglike:
age
numCategories 9
signFeatures c(1,2,3)
nullDeviance NA
residualDeviance NA
aic NA
I tried doing the below:
df['signFeatures', 'age'] <- c(1,2,3) &
df['signFeatures', 'age'] <- Vectorize(c(1,2,3))
Both the time it gives me the same error:
Error in `[<-.data.frame`(`*tmp*`, "signFeatures", "age", value = c(1, :
replacement has 3 rows, data has 1
I understand the problem, but cant find a way to solve it.
Any help would be appreciated
Like Andrew mentioned above, each column of a data frame has to have to same class, so you can record, instead, a transposed version of your desired table above:
data <- data.frame(numCategories = 9)
data$signFeatures <- list(c(1,2,3))
data$nullDeviance <- rnorm(1)
data$residualDeviance <- rnorm(1)
data$aic <- rnorm(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With