How to use make.names() function In R Language
We can do this by using make.names() function.
Syntax: make.names(colnames(dataframe))
Where, dataframe is the input dataframe
Example: R program to replace dataframe column names using make.names
R
# create a dataframe with 4 columns and 3 rows data = data.frame ( "web technologies" = c ( "php" , "html" , "js" ), "backend tech" = c ( "sql" , "oracle" , "mongodb" ), "middle ware technology" = c ( "java" , ".net" , "python" ), check.names = FALSE ) # replace blank by using make.names print ( make.names ( colnames (data))) |
Output:
[1] “web.technologies” “backend..tech” “middle.ware.technology”
Replace Spaces in Column Names in R DataFrame
In this article, we will replace spaces in column names of a dataframe in R Programming Language.
Let’s create a Dataframe with 4 columns with 3 rows:
R
# create a dataframe with 4 columns and 3 rows data = data.frame ( "web technologies" = c ( "php" , "html" , "js" ), "backend tech" = c ( "sql" , "oracle" , "mongodb" ), "middle ware technology" = c ( "java" , ".net" , "python" )) # display data |
Output:
In the above example, we can see that there are blank spaces in column names, so we will replace that blank spaces