Jim421616

Trying to rename columns in R

Jul 7th, 2020
2,396
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(tidyverse)
  2. library(data.table)
  3.  
  4. ugriz <- read.table("QSOs_1st_50k.dat-mags.dat")
  5. ugriz <- data.frame(ugriz)
  6. fields = c('name', 'z','delta_z','NED_class','SDSS_class','no_radio','radio_max','no_UV', 'UV_min',
  7.           'u', 'g', 'r', 'i', 'z_mag', 'I', 'J', 'H', 'K', 'W1', 'SPIT_5',
  8.           'W2', 'SPIT_8', 'W3', 'W4', 'NUV', 'FUV')
  9.  
  10. rename(ugriz, ned = V1, redshift = V2) # this works fine
  11.  
  12. # attempt 1 (tried with and without the quotes):
  13. rename(ugriz, c('name', 'z', 'delta_z', 'NED_class', 'SDSS_class', 'no_radio', 'radio_max', 'no_UV', 'UV_min',
  14.                 'u','g','r','i','z_mag','I','J','H','K', 'W1', 'SPIT_5',
  15.                 'W2','SPIT_8', 'W3', 'W4', 'NUV', 'FUV'), c('V1':'V26'))
  16. # attempt 2:
  17. setnames(ugriz, old = c('V1':'V26'), new = fields)
RAW Paste Data