cbind doesn't attribute the name of the column

I'm trying to create a new data frame that contains the row names and the first column of an existing data : i tried this

#To take the rownames of my old data
New_data - as.data.frame(row.names(old_data))
#To add the first column of my old data to a new data
New_data - cbind(old_data[,1])

When i visualize my new data using View(New_Data) i don't see the name of my the first column just V1

example

 old_data
   NAME  AGE  SEXE  
A   AQ   22    M
B   RT   14    M
C   DS   26    F
D   YY   19    M
E   IO   32    F
F   PP   20    F

New_data - as.data.frame(row.names(old_data))
New_data 
A
B
C
D
E
F

#add the first column of my old data to a new data

New_data - cbind(old_data[,1])
New_data
       V1
A      22
B      14
C      26
D      19
E      32
F      20

As you can see the name of the column in my new data is V1 , i want to bind the first column of my old data with the name of this column like this

New_data
           Name
    A      22
    B      14
    C      26
    D      19
    E      32
    F      20

Topic data programming statistics r

Category Data Science


The issue is not with cbind but rather with old_data[,1]. Since you are selecting only 1 column R will convert it into a vector, and a vector has no column name. Try cbind(old_data[,1,drop=F]).

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.