I have an R dataframe(df) which includes a factor column, Team
Team
Baltimore Orioles
Kansas City Chiefs
...
I just want to create a new column, nickname, which just refers to the last name
Nickname
Orioles
Chiefs
As a first stage, I have tried splitting the factor like this
df$Nickname <- strsplit(as.character(df$Team), " ")
which produces a list of character fields which I can reference thus
>df$Nickname[1]
[[1]]
[1] "Baltimore" "Orioles"
and
>str(df$Nickname[1])
List of 1
$ : chr [1:2] "Baltimore" "Orioles"
but then I do not know how to proceed. Trying to get the length
length(df$Nickname[1])
gives 1 - which flummoxes me
length(df$Nickname[[1]])orsapply(df$Nickname, length).