替换 R 中的一整列 [英] Replacing a whole column in R

查看:28
本文介绍了替换 R 中的一整列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多,但没有找到答案.假设我们有一些来自 .csv 文件的数据(我们称之为 xx.csv).像这样

I have searched a lot and I didn't find an answer on this. Let's say we have some data from a .csv file(lets call it xx.csv). Something like this

Number  A  B  C ... Z
 1     .. ..  ..
 .
 .
 .
4000  .. ..  .. ... ...

您可以在 A、B、C、...名称、数字、NA 等中放入任何您想要的内容.那么,用另一列外部(我的意思不是来自 csv 文件的列)替换一整列(假设 B)的最简单方法是什么??

You can put whatever you want in A, B, C,...Names, numbers, NAs etc. So, Whats the easiest way that I replace a whole column (lets say B) with another one external (I mean not one from the csv file)??

推荐答案

With assignment:

With assignment:

data$B <- whatever
# or
data[, "B"] <- whatever
# or
data[["B"]] <- whatever

这篇关于替换 R 中的一整列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆