-1

How would I alter these strings to remove all characters before the . and replace with the first letter of each

for example to make Alexander.Mattison turn into A.Mattison and so on..

thank you for your time..

data below..

> dput(rb2019capa)
structure(list(rusher_player_name = c("Aaron.Jones", "Adrian.Peterson", 
"Alexander.Mattison", "Alvin.Kamara", "Austin.Ekeler", "Brian.Hill"
), Team = c("Packers", "Redskins", "Vikings", "Saints", "Chargers", 
"Falcons"), `Salary Cap Value` = c(695487, 1780000, 700545, 1050693, 
646668, 645000), `Cash Spent` = c(645000, 2530000, 1317180, 807500, 
645000, 645000)), spec = structure(list(cols = list(Player = structure(list(), class = c("collector_character", 
"collector")), Team = structure(list(), class = c("collector_character", 
"collector")), `Salary Cap Value` = structure(list(), class = c("collector_number", 
"collector")), `Cash Spent` = structure(list(), class = c("collector_number", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), skip = 1), class = "col_spec"), row.names = c(1L, 
4L, 6L, 7L, 10L, 16L), class = c("spec_tbl_df", "tbl_df", "tbl", 
"data.frame"))
  • How is this different from [your earlier post](https://stackoverflow.com/questions/60329945/joining-on-inexact-strings-in-r). Please don't double-post. People have commented on your previous post attempting to help. Instead of reposting a nearly identical question, edit your previous question. – Maurits Evers Feb 21 '20 at 02:01
  • it is not different.. understood – sbarbarotta Feb 21 '20 at 02:10

1 Answers1

1

We can use sub to extract the first character and everything after ".".

sub("(.).*\\.(.*)", "\\1.\\2", rb2019capa$rusher_player_name)
#[1] "A.Jones"    "A.Peterson" "A.Mattison" "A.Kamara"   "A.Ekeler"   "B.Hill" 
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213