How to remove ".x" from column names in the dataframe?

T-T

I'm working on a large data set. While using as.yearmonto combine values from the same month, I have to usemake.unique(names(df))to create unique names for each column. From names(df), I can see that ".x",".y",".1",".2"etc. were added to some of the column names.

I can use gsub(".x","",names(df),fixed = TRUE)to remove ".x",".y", but the problem is that my column names are numeric like:

 name 1.0   1.1   1.2

With ".1",".2", the column names become:

 name 1.0.1   1.1.1   1.2.2

If I use gsub(".1","",names(df),fixed = TRUE) and gsub(".2","",names(df),fixed = TRUE), the colume names will then become:

 name 1.0   1   1

My question is that if there is a way to removed the added ".1", ".2" from the column names without changing the original names?

Ben Bolker

How about making sure you're only removing tags at the end of a label?

ndf <- c("1.0.1","1.1.1","1.2.2")
gsub("\\.[0-2]$","",‌​ndf)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to remove '.' from column names in a dataframe?

From Dev

How to remove column names from a matrix in R?

From Dev

how to remove table names from column names in beeline query results

From Dev

Remove column names from string

From Dev

Remove column names from string

From Dev

R How to remove characters from long column names in a data frame

From Dev

How to remove non-ASCII characters and space from column names

From Dev

How to remove trailing space from SQL or javascript object column names

From Dev

Remove .x from a column

From Dev

How to prevent Pandas Dataframe from repeating column names at every row?

From Dev

How to combine data from another dataframe by calling column names in r

From Dev

Remove last two characters from column names of all the columns in Dataframe - Pandas

From Dev

Remove last two characters from column names of all the columns in Dataframe - Pandas

From Dev

How do I remove/omit the count column from the dataframe in Pandas?

From Dev

How to remove string value from column in pandas dataframe

From Dev

How to remove a character from some rows in a dataframe column?

From Dev

How to remove timezone from a Timestamp column in a pandas dataframe

From Dev

How to remove comma or any characters from Python dataframe column name

From Dev

how to remove a column from Pandas dataframe using Python?

From Dev

Bar plot from dataframe, where x axis are column names and legend are indexes

From Dev

Build list from column names Pandas DataFrame

From Dev

How to create a new pandas dataframe from old dataframe using a list of column names

From Java

How to change dataframe column names in pyspark?

From Dev

How to change column names in dataframe in the loop?

From Dev

How to get the column names of a DataFrame GroupBy object?

From Dev

how to get numeric column names in pandas dataframe

From Dev

how to assign hierarchical column names in pandas dataframe

From Dev

How to prepend a string to column names for dataframe in R

From Dev

How to assign values of series to column names of dataframe

Related Related

  1. 1

    How to remove '.' from column names in a dataframe?

  2. 2

    How to remove column names from a matrix in R?

  3. 3

    how to remove table names from column names in beeline query results

  4. 4

    Remove column names from string

  5. 5

    Remove column names from string

  6. 6

    R How to remove characters from long column names in a data frame

  7. 7

    How to remove non-ASCII characters and space from column names

  8. 8

    How to remove trailing space from SQL or javascript object column names

  9. 9

    Remove .x from a column

  10. 10

    How to prevent Pandas Dataframe from repeating column names at every row?

  11. 11

    How to combine data from another dataframe by calling column names in r

  12. 12

    Remove last two characters from column names of all the columns in Dataframe - Pandas

  13. 13

    Remove last two characters from column names of all the columns in Dataframe - Pandas

  14. 14

    How do I remove/omit the count column from the dataframe in Pandas?

  15. 15

    How to remove string value from column in pandas dataframe

  16. 16

    How to remove a character from some rows in a dataframe column?

  17. 17

    How to remove timezone from a Timestamp column in a pandas dataframe

  18. 18

    How to remove comma or any characters from Python dataframe column name

  19. 19

    how to remove a column from Pandas dataframe using Python?

  20. 20

    Bar plot from dataframe, where x axis are column names and legend are indexes

  21. 21

    Build list from column names Pandas DataFrame

  22. 22

    How to create a new pandas dataframe from old dataframe using a list of column names

  23. 23

    How to change dataframe column names in pyspark?

  24. 24

    How to change column names in dataframe in the loop?

  25. 25

    How to get the column names of a DataFrame GroupBy object?

  26. 26

    how to get numeric column names in pandas dataframe

  27. 27

    how to assign hierarchical column names in pandas dataframe

  28. 28

    How to prepend a string to column names for dataframe in R

  29. 29

    How to assign values of series to column names of dataframe

HotTag

Archive