How to rename column in data frame with R

1 Answer

0 votes
df = data.frame(a = c(1, 3, 4, 7),
                b = c(12, 98, 87, 20),
                c = c(2, 4, 5, 9),
                d = c(13, 77, 50, 20),
                row.names = c('o', 'p', 's', 't'))
  
print(df)
  
colnames(df)[2] <- 'R'
  
print(df)
  
  
  
        
        
# run:
#
#   a  b c  d
# o 1 12 2 13
# p 3 98 4 77
# s 4 87 5 50
# t 7 20 9 20
#   a  R c  d
# o 1 12 2 13
# p 3 98 4 77
# s 4 87 5 50
# t 7 20 9 20
#

 



answered Jul 10, 2021 by avibootz

Related questions

1 answer 340 views
1 answer 268 views
1 answer 310 views
1 answer 394 views
1 answer 306 views
306 views asked Jul 9, 2021 by avibootz
1 answer 340 views
1 answer 356 views
...