If there are many columns in your data.frame that have attributes you want to preserve, you could use lapply (EDITED to include original column class):mydf2 <- data.frame( lapply( mydf, function(x) { structure( x, class = c("avector", class(x) ) )} ) )然而,这会丢弃与 data.frame 本身相关的注释(例如 comment(mydf)<-"I'm a data.frame"),因此如果您有任何注释,请分配他们到新的 data.frame:However, this drops comments associated with the data.frame itself (such as comment(mydf)<-"I'm a data.frame"), so if you have any, assign them to the new data.frame:comment(mydf2)<-comment(mydf)然后你有> str(mydf2[1:2,])'data.frame': 2 obs. of 2 variables: $ aa:Classes 'avector', 'numeric' atomic [1:2] 3 3 .. ..- attr(*, "comment")= chr "Don't drop me!" $ bb: Factor w/ 5 levels "A","B","C","D",..: 4 2 ..- attr(*, "comment")= chr "Me either!" - attr(*, "comment")= chr "I'm a data.frame" 这篇关于如何从data.frame中删除一行而不丢失属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!