You can reset the rownames in a data frame by running
>rownames(df) <- NULL
I have a list of dataframes and want to reset all the rownames on every dataframe in the list, I tried
>newlist <- llply(mylist, function(df) { rownames(df) <- NULL })
Bu tit doesn't work, returns a list of NULLS and the original remains unchanged.
This is a job for the base function lapply
; you don't need to load plyr. You also need to make sure that your anonymous function returns something.
df1 <- data.frame(a=1:10)
rownames(df1) <- letters[1:10]
df2 <- data.frame(b=1:10)
rownames(df2) <- LETTERS[1:10]
mylist <- list(df1,df2)
mylist <- lapply(mylist,function(DF) {rownames(DF) <- NULL; DF})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With