Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6624111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:36:47+00:00 2026-05-25T21:36:47+00:00

I have an R dataframe(df) which includes a factor column, Team Team Baltimore Orioles

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:36:47+00:00Added an answer on May 25, 2026 at 9:36 pm

    you just need to unlist the split strings and take the last one

        full <- c("Baltimore Orioles","Kansas City Chiefs")
        getlast <- function(x){
        parts <- unlist(strsplit(x, split = " "))
        parts[length(parts)]
        }
        sapply(full,getlast)
        > Baltimore Orioles Kansas City Chiefs 
        > "Orioles"           "Chiefs" 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a column in a dataframe that contains an ordered factor. I summarize
I have a dataframe called prices_df to which I add an extra column and
I have a dataframe with a column of integers that I would like to
I have a 3 column data frame which looks a little like this: id
In R I am trying to delete rows within a dataframe (ants) which have
I have a dataframe, and I want to produce a table of summary statistics
I have a data frame with several columns, one of which is a factor
I have a data.frame called series_to_plot.df which I created by combining a number of
I have a dataframe with numeric entries like this one test <- data.frame(x =
Suppose I have a dataframe like this one: df <- data.frame (id = c(a,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.