Can anyone help me with this simple task.
I'm getting started in r, and I can't understand why this part of code isn't running inside a loop for.
I've tried to use the function strsplit()
out of the loop and it worked well, but I'm not succeding in running the code the way I would like to, inside a for loop, in a data frame.
Here is the code:
mpg <- ggplot2::mpg
df_sort <- data.frame(uni_model = sort(unique(mpg$model)))
df_sort$model1 <- ''
for (x in seq_along(df_sort$model)){
df_sort[x, 'model1'] <- strsplit(df_sort[x, 'model'], ' ')
}