-1

I want to remove the date part from the first column but can't do it for all the dataset?

can someone advise please?

Example of dataset:

Matt
  • 7,255
  • 2
  • 12
  • 34
  • Hello, please, put your data here as a plain text, not a screenshot - it's better for searching for the other people. Also please add a desired output you want to get. See [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and [How to ask](https://stackoverflow.com/help/how-to-ask). Just edit your question above. Thanks a lot in advance! –  Jul 29 '20 at 17:51

1 Answers1

0

You can use sub() function with replacing ^[^[:alpha:]]+ (regular expression, i.e. all non-alphabetic characters at the beginning of the string), with "", i.e. empty string.

sub("^[^[:alpha:]]+", "", data)

Example

data <- data.frame(
  good_column = 1:4,
  bad_column = c("13/1/2000pasta", "14/01/2000flour", "15/1/2000aluminium foil", "15/1/2000soap"))

data
#>   good_column              bad_column
#> 1           1          13/1/2000pasta
#> 2           2         14/01/2000flour
#> 3           3 15/1/2000aluminium foil
#> 4           4           15/1/2000soap

data$bad_column <- sub("^[^[:alpha:]]+", "", data$bad_column)

data
#>   good_column     bad_column
#> 1           1          pasta
#> 2           2          flour
#> 3           3 aluminium foil
#> 4           4           soap

Created on 2020-07-29 by the reprex package (v0.3.0)