Reputation: 43
I've searched on google, here and on youtube but I've not seen anyone ask this, thus I doubt it is possible. But I have a data frame with a decent number of rows (25) and I'm making a correlation plot between the numerical variables and a heat map of Chi-Squared Test p-values between the categorical variables.
To do so I need to refer to the column ID for each relevant variable. I'm just wondering if there is a way to make the View() function display column numbers by default, similar to how there is an index column for row numbers.
Thank you for your time
Upvotes: 1
Views: 874
Reputation: 41210
You could label the columns, as View
displays labels:
library(labelled)
var_label(iris) <- as.list(setNames(as.character(1:ncol(iris)),colnames(iris)))
View(iris)
Upvotes: 1
Reputation: 8676
Here is an option:
set.seed(42)
# example dataframe
df_0 <- data.frame(x = rnorm(3),
y = rnorm(3),
z = rnorm(3))
# copy to leave original copy intact
df_1 <- df_0
# rename columns with indices
colnames(df_1) <- 1:ncol(df_1)
# produces
df_1
#> 1 2 3
#> 1 1.3709584 0.6328626 1.51152200
#> 2 -0.5646982 0.4042683 -0.09465904
#> 3 0.3631284 -0.1061245 2.01842371
View(df_1)
Created on 2021-02-19 by the reprex package (v1.0.0)
Upvotes: 0