简体   繁体   English

如何将一个data.table中的列中的某些行添加到标题下的另一个data.table中?

[英]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.

相关问题 如何从一个data.table中选择行以应用于另一data.table? - How to select rows from one data.table to apply in another data.table? 如何用相同维度的另一个数据表的值替换一个数据表中的某个值 - How to replace a certain value in one data.table with values of another data.table of same dimension 如何最好地将data.table的一列与同一data.table的另一列连接? - How to best join one column of a data.table with another column of the same data.table? 如果 data.table 中的选定行与另一个 data.table 中的值匹配,如何更新它们 - How to update selected rows in a data.table if they match value from another data.table 通过R data.table中的ID删除重复的行,但添加一个新列,并将其连接的日期与另一列 - Remove duplicated rows by ID in R data.table, but add a new column with the concatenated dates from another column 如何从 data.table 中排除一列或转换为 data.table 到 MTS - How to exclude one column from data.table OR convert to data.table to MTS 如何使用 data.table 将一列替换为另一列? - How to replace one column with another using data.table? 根据另一个data.table删除data.table中的行 - Remove rows in data.table according to another data.table 在 data.table 中:迭代另一个 data.table 的行 - In data.table: iterating over the rows of another data.table 从data.table中删除一列上相同但在另一列上不同的行 - remove rows that are same on one column but different on another from a data.table
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM