为什么 Replace() 函数将我的数据帧转换为原子向量?
我有这样的代码:
s12 <- replace(s12$nautos, s12$nautos == 11, 1) # this one does not produce error
s12 <- replace(s12$nautos, s12$nautos == 22, 2) # this one produces error that I cannot use $ because s12 is an atomic vector
再次运行它们都会产生错误。
当我查看全局环境时,s12 数据帧现在是一个向量。
为什么会发生这种情况?
nautos 列是一个包含 3000 个值的列,可以采用任意数字,但所有答案都是 0-4,除了两个条目 11 和 22,我认为这两个条目是拼写错误,应该是 1 和 2。
I have this code:
s12 <- replace(s12$nautos, s12$nautos == 11, 1) # this one does not produce error
s12 <- replace(s12$nautos, s12$nautos == 22, 2) # this one produces error that I cannot use $ because s12 is an atomic vector
Running them both again produces the error for both.
When I look at the global environment, s12 dataframe is now a vector.
Why did this happen?
column nautos is a column with 3000 values that takes any number, but all answers are 0-4 except for two entries that are 11 and 22, which I assume are typos and meant to be 1 and 2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论