Specifying column number in Principal Component Analysis in R

I am carrying out PCA in R. Instead of carrying out PCA from Columns 7-30, I want to select Column number 4 and 15-30. How can I adjust the columns in the code

clim_data <- read.csv("MergedCSV_43X47Y_CanESM.csv")
str(clim_data)
colSums(is.na(clim_data))
numerical_data <- clim_data[,7:30]
head(numerical_data)
data_normalized <- scale(numerical_data)
head(data_normalized)
corr_matrix <- cor(data_normalized)
ggcorrplot(corr_matrix)

>Solution :

to select specific columns you could specify using c() :

numerical_data <- clim_data[,c(4,15:30)]

Leave a Reply