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

前端 未结 10 1747
陌清茗
陌清茗 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:27
    1. In RStudio, ensure the Environment tab is in Grid (not List) mode.

    2. Tick the object(s) you want to remove from the environment.

    3. Click the broom icon.

    0 讨论(0)
  • 2020-12-04 06:29

    To clear all data:

    click on Misc>Remove all objects.

    Your good to go.

    To clear the console:

    click on edit>Clear console.

    No need for any code.

    0 讨论(0)
  • 2020-12-04 06:34
    paste0("data_",seq(1,3,1)) 
    # makes multiple data.frame names with sequential number
    rm(list=paste0("data_",seq(1,3,1))
    # above code removes data_1~data_3
    
    0 讨论(0)
  • 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()
    
    0 讨论(0)
提交回复
热议问题