0

My input data is in the format shown in the left column. I would like the data to be in the format shown in the right column.

How can I do that?

I have data in this format: Here is how I want the data to appear:

Here is my dput:

structure(list(Player = structure(c(7L, 16L, 13L, 9L, 12L, 15L, 
11L, 6L, 2L, 3L, 10L, 8L, 4L, 1L, 5L, 14L), .Label = c("Alberto Castillo\\castial01", 
"B.J. Surhoff\\surhob.01", "Bobby Bonilla\\bonilbo01", "Chipper Jones\\jonesch06", 
"David Segui\\seguida01", "Eddie Perez\\perezed02", "Felix Jose\\josefe01", 
"Garret Anderson\\anderga01", "John McDonald\\mcdonjo03", "Keith Lockhart\\lockhke01", 
"Luis Gonzalez\\gonzalu01", "Mark Grace\\gracema01", "Matt Williams\\willima04", 
"Melvin Mora\\morame01", "Steve Finley\\finlest01", "Tony Clark\\clarkto02"
), class = "factor"), G = c(13L, 36L, 44L, 70L, 145L, 150L, 155L, 
16L, 25L, 114L, 128L, 135L, 143L, 11L, 18L, 125L), Year = c(2002L, 
2009L, 2003L, 2012L, 2001L, 2002L, 2005L, 2005L, 2002L, 2000L, 
2002L, 2009L, 2009L, 2007L, 2004L, 2009L), Age = c(37L, 37L, 
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 
37L)), class = "data.frame", row.names = c(NA, -16L))
Metsfan
  • 510
  • 2
  • 8
  • 1
    try `sub('\\\\.*', '', df$Player)` – Sotos Feb 28 '20 at 14:19
  • 1
    `dput$Player <- sub("\\\\.*", "", dput$Player)` – altfi_SU Feb 28 '20 at 14:43
  • altfi, that is what I need. Thank you very much. I had looked at the post at https://stackoverflow.com/questions/17187552/removing-everything-after-first-backslash-in-a-string but that did not clarify things for me. – Metsfan Feb 28 '20 at 14:49

0 Answers0