为行的子集创建两个变量中的新变量
我需要从两个旧变量的 value>中创建一个新变量(var_new)(var_old_1; var_old_2),但在这两种情况下,仅对于行的一个子集。
让我解释一下:
我有一个索引变量,指示患者代码;称为“患者代码”(H01,H02,H03 ...)
我需要创建一个新变量。 “ var_new”
必须从var_old_1或var_old_2分配新变量“ var_new”的值。
。
因此
(H01,H02,H04)var_new == var_old_1 对于(H03,H05)var_new == var_old_2
dertaborcode | var_old_1 | var_old_2 | var_new |
---|---|---|---|
H01 | 1.1 | 1.1 | 2.1 1.1 |
H02 | 1.2 1.2 | 2.2 | 1.2 1.2 |
H03 | 1.3 | 1.3 2.3 | 2.3 2.3 |
H04 | 1.4 1.4 | 2.4 2.4 1.4 | 1.4 |
H05 | 1.5 1.5 2.5 | 2.5 2.5 | 2.5 |
这只是一个示例。在我的数据集中,我要处理300行,我需要在此方案之后创建32个新变量。因此,一个好的代码将有所帮助。
I need to create a new variable (Var_new) out of the values of two old variables (Var_Old_1; Var_Old_2) but in both cases only for a subset of rows.
Let me explain:
I have an index variable, indicating the patient code; called "patientcode" (H01, H02, H03 ...)
I need to create a new variable. "Var_new"
the values of the new Variable "Var_new" must be assigned from Var_Old_1 or Var_Old_2 depending on the index variable.
So e.g.
for (H01, H02, H04) Var_new == Var_Old_1
for (H03, H05) Var_new == Var_Old_2
patientcode | Var_Old_1 | Var_Old_2 | Var_new |
---|---|---|---|
H01 | 1.1 | 2.1 | 1.1 |
H02 | 1.2 | 2.2 | 1.2 |
H03 | 1.3 | 2.3 | 2.3 |
H04 | 1.4 | 2.4 | 1.4 |
H05 | 1.5 | 2.5 | 2.5 |
This is only an example. In my dataset I'am dealing with 300 rows and I need to create 32 new variables following this scheme. so a good code would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许有以下内容?
然而,如果您需要以这种方式创建32个新变量,您的描述听起来好像您需要进行大量手动预订?也许想想是否需要创建这些VAR的方式背后有任何规律性。否则,我看不到如何避免进一步的手动努力。
Maybe something like the following?
Yet your description sounds like you need to do lots of manual prework if you need to create 32 new variables that way?! Maybe think about if there's any kind of regularity behind the way those vars need to be created. Otherwise I don't see a possibility how to avoid further manual efforts.