当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 rm()用法及代码示例


rm()R语言中的函数用于从内存中删除对象。它可以与ls()函数删除所有对象。remove()函数也类似于rm()函数。

用法: rm(x)

参数:
x:对象名称

范例1:


# R Program to remove 
# objects from Memory
  
# Creating a vector
vec <- c(1, 2, 3, 4)
vec
  
# Creating a list
list1 = list("Number" = c(1, 2, 3),
             "Characters" = c("a", "b", "c"))
list1
  
# Creating a matrix
mat <- matrix(c(1:9), 3, 3)
mat
  
# Calling rm() Function
rm(list1)
  
# Calling ls() to check object list
ls()

输出:

[1] 1 2 3 4
$Number
[1] 1 2 3

$Characters
[1] "a" "b" "c"

     [, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9
[1] "mat" "vec"

范例2:


# R Program to remove 
# objects from Memory
  
# Creating a vector
vec <- c(1, 2, 3, 4)
  
# Creating a list
list1 = list("Number" = c(1, 2, 3),
             "Characters" = c("a", "b", "c"))
  
# Creating a matrix
mat <- matrix(c(1:9), 3, 3)
  
# Calling rm() Function
# to remove all objects
rm(list = ls())
  
# Calling ls() to check object list
ls()

输出:

character(0)



相关用法


注:本文由纯净天空筛选整理自nidhi_biet大神的英文原创作品 Remove Objects from Memory in R Programming – rm() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。