I have a dataframe df with 50 columns, and I would like to generate vector objects for each column name, with the length of the dataframe rows.
My code throws out an error:
for i in ((1:ncol(df)) {
colnames(df)[i] <- vector(mode = "list", length = nrow(df))
return (colnames(df)[i])
}
The error:
for i in ((1:ncol(df)) { Error: unexpected symbol in "for i" colnames(df)[i] <- vector(mode = "list", length = nrow(df)) Error in colnames(df)[i] <- vector(mode = "list", length = nrow(df)) :
object 'i' not found return (colnames(df)[i]) Error: object 'i' not found } Error: unexpected '}' in "}"
P.S. Some of the columns in my dataframe are nested lists, just in case this affects the operation.
df?, Is not clear what you want to achieve? - S Rivero