timnitiguo
timnitiguo

Reputation: 23

remove same information in my data

I tried to clean my data in R, my data looks like this

  CustomerNumber  Revenue
    Customer1       3
    Customer2       4
    Customer3       5

How can I remove all the "Customer" in "Customer1" and make it like this

    CustomerNumber  Revenue
        1              3
        2              4
        3              5

I tried to Google the answer, but can't find anything.

Upvotes: 0

Views: 28

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388982

You could probably just replace the word "Customer" with an empty space using gsub. Assuming df as your data.frame you can try,

df$CustomerName <- gsub("Customer", "", df$CustomerNumber)
df
# CustomerNumber  Revenue
#    1              3
#    2              4
#    3              5

Upvotes: 1

Related Questions