How do I clear only a few specific objects from the workspace?

前端 未结 10 1757
陌清茗
陌清茗 2020-12-04 05:53

I would like to remove some data from the workspace. I know the \"Clear All\" button will remove all data. However, I would like to remove just certain data.

For exa

10条回答
  •  感情败类
    2020-12-04 06:36

    If you just want to remove one of a group of variables, then you can create a list and keep just the variable you need. The rm function can be used to remove all the variables apart from "data". Here is the script:

    0->data
    1->data_1
    2->data_2
    3->data_3
    #check variables in workspace
    ls()
    rm(list=setdiff(ls(), "data"))
    #check remaining variables in workspace after deletion
    ls()
    
    #note: if you just use rm(list) then R will attempt to remove the "list" variable. 
    list=setdiff(ls(), "data")
    rm(list)
    ls()
    

提交回复
热议问题