How to rename a single column in a data frame

0 votes
I'm aware that if I have a data frame with more than one column, I can make use of

colnames(x) - colnames(x) - colnames(x) - colnames(x ("col1","col2")

to change the names of the columns If there is only one column, how do you do it? A vector or data frame with only one column is referred to as a single-column vector or data frame.

Example:

trSamp - data.frame(sample(trainer$index, 10000), trSamp - trSamp - trSamp - trSamp - trSamp

the top (trSamp )

# sample.trainer.index..10000; # sample.trainer.index..10000; # sample.trainer.index

5907862 is a telephone number.

2181266# 2181266# 2181266# 2181266

7368504 is the third number.

1949790 (#4)

3475174 # 5

6062879 is a telephone number.

ncol(trSamp)

1 # [1]

class(trSamp)

# "data.frame" is the first item on the list.

class(trSamp[1])

# "data.frame" is the first item on the list.

class(trSamp[,1])

# [numeric] # [numeric] # [numeric] # [numeric] #

colnames(trSamp)[2] - "newname2" colnames(trSamp)[2] - "newname2"

# Names(x) error - value:

# The length of the 'names' property [2] must be the same as the vector [1].

I'm aware that if I have a data frame with more than one column, I can make use of

colnames(x) - colnames(x) - colnames(x) - colnames(x ("col1","col2")

to change the names of the columns If there is only one column, how do you do it? A vector is a type of data that can be represented in a number of
Jun 10 in Data Analytics by Avinash
• 1,060 points
9 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Data Analytics

0 votes
2 answers

How to subset rows containing NA in a chosen column of a data frame?

You can give this a try. subset(dataframe, is.na(dataframe$col2)) ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,010 points
7,597 views
0 votes
1 answer

How to replace all occurrences of a character in a character column in a data frame in R

If you used sub() to replace the ...READ MORE

answered Jun 29, 2019 in Data Analytics by anonymous
• 33,010 points
16,119 views
0 votes
1 answer
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,012 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,010 points
851 views
+1 vote
3 answers

How to change column names of a Data frame?

Hi, To change the name of a column ...READ MORE

answered Oct 30, 2020 in Data Analytics by MD
• 95,360 points
707 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
421 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
466 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
4,279 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
490 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP