Renaming last rows

时间:2016-08-31 17:30:33

标签: rowname

it might be a stupid question, but I was wondering whether there is any way that I can specify that I want to rename only the last row from my data frame. I have an object storing a list of data frames of various nr of rows.

Thanks a lot!

1 个答案:

答案 0 :(得分:0)

It would be much better if you provided example code of what you have and said which language you were using, but I think what you are trying to do is something like this in R:

df_list <- list(df1 = data.frame(x = 1:2), df2 = data.frame(y = 1:3))
nrows <- sapply(df_list, nrow)
rownames(df_list[[1]])[nrows[1]] <- "last_df1"
rownames(df_list[[2]])[nrows[2]] <- "last_df2"

Of course the last part can be put in an apply function or loop if you have to do it for a lot of entries in the list.