What is the difference between rm() and rm(list=ls())?

前端 未结 2 1173
灰色年华
灰色年华 2020-12-30 06:16

Most of articles, I have read. They recommend to use rm(list=ls()) but I do not know what is the difference if I like to use rm()

Can I use

2条回答
  •  遥遥无期
    2020-12-30 07:01

    rm() is basically 'remove{base}', it is used to Remove Objects from a Specified Environment.

    Command rm(list=ls()) means-

    list=ls() is base in this command that means you are referring to all the objects present in the workspace.

    similarly, rm() is used to remove all the objects from the workspace when you use list=ls() as base.

    However, when it comes to using rm() alone it will not do anything as the 'base' is absent.

    You can use rm() to remove specific variables to by putting them as 'base':

    For example

    a <-45                                                                          
    rm(a)
    

提交回复
热议问题