复制矩阵与大矩阵
如果您想复制一个 big.matrix 对象,需要使用 deepcopy() 函数。这样做很有用,尤其当您想创建更小的 big.matrix 对象时。在本练习中,您将复制一个 big.matrix 对象,并展示此类对象的引用行为。
本练习是课程的一部分
R 的可扩展数据处理
练习说明
big.matrix 对象 mort 已在您的工作区中可用。
- 创建一个新变量
first_three,它是mort的显式副本,但只包含前三列。 - 将另一个变量
first_three_2设为first_three。 - 将
first_three的第 1 行第 1 列的值设为NA。 - 验证该更改会出现在
first_three_2中,但不会出现在mort中。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Use deepcopy() to create first_three
first_three <- ___(___, cols = ___,
backingfile = "first_three.bin",
descriptorfile = "first_three.desc")
# Set first_three_2 equal to first_three
___ <- ___
# Set the value in the first row and first column of first_three to NA
first_three[___, ___] <- NA
# Verify the change shows up in first_three_2
first_three_2[1, 1]
# but not in mort
mort[1, 1]