简体   繁体   English

根据R中的唯一值将一列数据细分为多个列

[英]Segmenting a column Data into multiple columns based on unique value in R

I have a dataset of the form: 我有一个形式的数据集:

Dataset 1 数据集1

I need to convert the above data into the following in R: 我需要将以上数据转换为R中的以下数据:

Dataset 2 数据集2

How can it be done? 如何做呢? It should be simple but I am not able to figure out the correct function or steps to do this. 它应该很简单,但是我无法弄清楚执行此操作的正确功能或步骤。 Any help would be much appreciated. 任何帮助将非常感激。 Thank you 谢谢

I'd use data.table for this: 我会为此使用data.table:

library(data.table)
df1 = data.frame("A"=c(1,1,1,2,2),"B"=6:10)

df2 = data.table::dcast(df1,B~A,value.var="B")

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改具有唯一值的多列中的值并合并为单列 (R) - Change values in multiple columns with unique value and merge into single column (R) 将列值除以R中多个列的唯一数目 - Dividing a column value by unique number of multiple columns in R 基于多列/行为新列分配唯一值 - assigning unique value to new column based on multiple columns/rows 基于多个列的布尔值选择列值-R - select column value based on boolean values multiple columns - R 根据 R 中第三列的值复制数据框的列 - Copy columns of a data frame based on the value of a third column in R 在 R 中,如何根据多列中的时间和日期值创建具有唯一值的列 - In R how do you create a column with unique values based on time and date values in multiple columns 在R中如何将列的值应用于同一数据框中的多个列 - in R how to apply a value of a column to multiple columns in the same data frame 根据数据表中的多个列创建一个新的累积值列 - Create a new column of cumulative value based on multiple columns in data table 如何基于列名创建数据的多个子集,而无需在所述列(R)中指定所有唯一名称 - How to create multiple subsets of data based on a column name without specifying all the unique names in said column (R) R:如何根据单列中的唯一值组合来自多列的重复行,并通过 | 合并这些唯一值? - R: How to combine duplicated rows from multiple columns based on unique values in a single column and merge those unique values by |?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM