Renaming multiple columns with indices in R

后端 未结 3 518
醉话见心
醉话见心 2021-01-24 14:40

I scraped this data from a json file which feeded an interactive graphic.

df <- structure(list(x = c(\"Iraq\", \"Syria\"), Aug. = c(\"120\", \"12         


        
3条回答
  •  清歌不尽
    2021-01-24 15:01

    To change the column names of a data frame, you can do this:

    # Example data frame
    x <- as.data.frame(
        matrix(letters[1:10], nrow = 2)
        );
    
    # Change names of columns 2-5
    colnames(x)[2:5] <- paste0(colnames(x)[2:5], 1:4);
    # Change all column names
    colnames(x) <- paste0(colnames(x), 1:5);
    

提交回复
热议问题