I'm trying to write a for loop that drops each column in a data frame and saves the modified data frame to a new variable.
This code illustrates what I would like the loop to perform
df1 = df[,-1]
df2 = df[,-2]
df3 = df[,-3]
#failed loop syntax 1 (unexpected "[" in "df[i] = df[,-[")
for (i in 1:3){
df[i] = df[,-[i]]}
#failed loop syntax 2 (number of items to replace is not a multiple of replacement length)
for (i in 1:3){
df[i] = df[,-i]}
Can anyone help me with this? This is an example to illustrate what I would like to achieve. The real data set contains 28 rows and 64 columns. I am trying to see how removing any one of the 64 columns affects the distribution of the 28 items in a K Cluster plot. I've tried PCA plots, but they are relatively useless with the 64 vectors.
EDIT:
slava-kohut's code (pasted below)worked perfectly for the first problem. Can anyone help me loop the output of the below code into a series of K cluster plots with the data input listed as the plot title?
for (i in 1:64){
assign(paste0(deparse(substitute(mydata)),i),mydata[,-i])
}