I was dealing with a list of two dataframes. Both look this way.
What I would like to do was to change the row names and column names so that they may look this way.
Here is the code I used.
# Create a list to hold both dataframes
list_info <- c(normheart.info, disheart.info)
# Adjust the row and column names
list_info <- list_info %>% lapply(
FUN = function(x){
colnames(x) <- x[1,]
rownames(x) <- x[,1]
x <- x[-1,]
x <- x[,-1]
}
)
However, an error occurred as:
Error in x[1, ] : incorrect number of dimensions
I understand that the cause may be because lapply was trying looping through all the columns which have only 1 dimension. Is there a way to make it possible to have it recognize x
as the dataframe itself so I can specify the first row as the column names and so too to the row names?