[英]How to add certain rows from a column in one data.table to another data.table under a heading?
I am trying to paste certain values of a column of one data set (I need to be able to select 10-10k values dynamically from the first column) to another data set's column, but without overwriting the 2nd dataset's column value 1 (which is a header name). 我正在尝试将一个数据集的某个列的某些值粘贴(我需要能够从第一列动态选择10-10k个值)到另一个数据集的列,但不覆盖第二个数据集的列值1(即标头名称)。 Sometimes it will be just part of a column and not the entire column.
有时,它只是列的一部分,而不是整个列。 Some of the entries will be characters and some will be numerial.
一些条目将是字符,而某些条目将是数字。
data.table1: (no header row) data.table1 :(无标题行)
Row1: 21 32 77 ... 1293
Row2: 55 23 18 ... 2341
Row3: 87 29 41 ... 8283
Rows++: ... (10k+rows long)
data.table2: (has header row) data.table2 :(具有标题行)
Row1: header1 header2 header3 ... header50
Row2: 123 char1 531 ... char5
Row3: 520 char2 488 ... 876
Rows++: ... (10k+rows long)
Example of desired output, with column one containing values from data.table1 without overwriting header in row1 from data.table2: 所需输出的示例,其中第一列包含data.table1中的值,而不会覆盖data.table2中row1中的标头:
data.table3: data.table3:
Row1: header1 header2 header3 ... header50
Row2: 21 char1 531 ... char5
Row3: 55 char2 488 ... 876
Rows++: ... (10k+rows long)
I've found similar threads discussing using different methods to paste entire columns (meaning that the first row containing the header would be overwritten). 我发现类似的 线程正在讨论使用不同的方法粘贴整个列(这意味着包含标题的第一行将被覆盖)。
I will need to make many of these types of manipulations, and will also need to be able to do so for arbitrary data.table row locations. 我将需要进行许多此类操作,并且还需要能够对任意data.table行位置执行此操作。 So instead of just working with row2-row50 of column1, I will need to be able to also adjust row50-750 in column10 for example.
因此,不仅要处理column1的row2-row50,还需要例如能够调整column10的row50-750。 Is there a way to do this with data.table?
有没有办法用data.table做到这一点? Thank you
谢谢
A good friend was able to provide some advice about moving one column to another including the header: 一个好朋友能够提供有关将一列移动到另一列(包括标题)的一些建议:
data.table2$V57[2:nrow(data.table2)] <- data.table1$header3 data.table2 $ V57 [2:nrow(data.table2)] <-data.table1 $ header3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.