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 6153501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:06:17+00:00 2026-05-23T20:06:17+00:00

I have a vector with names, e.g.: names <- Jansen, A., Karel, A., Jong,

  • 0

I have a vector with names, e.g.:

names <- "Jansen, A., Karel, A., Jong, A. de, Pietersen, K."

And I want to split this per name. In this case, I need to split the vector on ., and the comma following de (That name would be A. De Jong, which is typical in Dutch).

Right now I do:

 strsplit(names,split="\\.\\,|\\<de\\>,")

But this also removes the de from the name:

[[1]]
[1] "Jansen, A"      " Karel, A"      " Jong, A. "     " Pietersen, K."

How can I obtain the following as result?

[[1]]
[1] "Jansen, A"      " Karel, A"      " Jong, A. de"     " Pietersen, K."
  • 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-23T20:06:17+00:00Added an answer on May 23, 2026 at 8:06 pm

    polishchuk’s regex needs two modifications to make it work in R.

    Firstly, the backslash needs escaping. Secondly, the call to strsplit needs the argument perl = TRUE to enable lookbehind.

    strsplit(names, split = "\\.,|(?<=de)", perl = TRUE)
    

    gives the answer Sacha asked for.

    Notice though that this still includes a dot in de Jong’s name, and it isn’t extensible to alternatives like van, der, etc. I suggest the following alternative.

    names <- "Jansen, A., Karel, A., Jong, A. de, Pietersen, K., Helsing, A. van"
    #split on every comma
    first_last <- strsplit(names, split = ",")[[1]]
    #rearrange into a matrix with the first column representing last names, 
    #and the second column representing initials
    first_last <- matrix(first_last, byrow = TRUE, ncol = 2) 
    #clean up: remove leading spaces and dots
    first_last <- gsub("^ ", "", first_last)
    first_last <- gsub("\\.", "", first_last)
    #combine columns again
    apply(first_last, 1, paste, collapse = ", ")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector that I want to insert into a set . This
I have a vector of integers and I want to convert it to a
I have a vector of beans that holds information I want to display in
I have a vector of pointers to a class. I need to call their
I have a vector of booleans. I need to set its elements from n-th
I have need to print indented template names for debugging purposes. For example, instead
i need to serialize directory tree. i have no trouble with this type: std::map<
I'd like to split a vector of character strings (people's names) into two columns
I have two vectors. vector<Object> objects; vector<string> names; These two vectors are populated and
I have an R question--I want to make a vector of functions, and then

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.