我使用下面的示例数据作为我的输入。
5 列 - 1) Part_ID 2)Station_ID 3)Time 4)Parameters 5)Values
<table><tbody><tr><th>Part_ID</th><th>Station_ID</th><th>Time</th><th>Parameters</th><th>Values</th></tr><tr><td>A_01</td><td>S_01</td><td>4/30/19 3:00 PM</td><td>ABC_01</td><td>10</td></tr><tr><td>A_01</td><td>S_01</td><td>4/30/19 3:05 PM</td><td>ABC_02</td><td>12</td></tr><tr><td>A_01</td><td>S_01</td><td>4/30/19 3:10 PM</td><td>ABC_03</td><td>11</td></tr><tr><td>A_01</td><td>S_01</td><td>4/30/19 3:15 PM</td><td>ABC_04</td><td>10</td></tr><tr><td>A_01</td><td>S_02</td><td>4/30/19 3:20 PM</td><td>XYZ_01</td><td>15</td></tr><tr><td>A_01</td><td>S_02</td><td>4/30/19 3:25 PM</td><td>XYZ_02</td><td>9</td></tr><tr><td>A_01</td><td>S_02</td><td>4/30/19 3:30 PM</td><td>XYZ_03</td><td>11.5</td></tr><tr><td>A_01</td><td>S_02</td><td>4/30/19 3:35 PM</td><td>XYZ_04</td><td>12.5</td></tr><tr><td>B_01</td><td>S_01</td><td>4/31/2019 3:00:00 PM</td><td>ABC_01</td><td>5</td></tr><tr><td>B_01</td><td>S_01</td><td>4/31/2019 3:06:00 PM</td><td>ABC_02</td><td>6</td></tr><tr><td>B_01</td><td>S_01</td><td>4/31/2019 3:12:00 PM</td><td>ABC_03</td><td>7</td></tr><tr><td>B_01</td><td>S_01</td><td>4/31/2019 3:18:00 PM</td><td>ABC_04</td><td>4.5</td></tr><tr><td>B_01</td><td>S_02</td><td>4/31/2019 3:24:00 PM</td><td>XYZ_01</td><td>5.5</td></tr><tr><td>B_01</td><td>S_02</td><td>4/31/2019 3:30:00 PM</td><td>XYZ_02</td><td>9</td></tr><tr><td>B_01</td><td>S_02</td><td>4/31/2019 3:36:00 PM</td><td>XYZ_03</td><td>6</td></tr><tr><td>B_01</td><td>S_02</td><td>4/31/2019 3:42:00 PM</td><td>XYZ_04</td><td>7</td></tr></tbody></table>
我想将此数据转换为以下输出数据格式,如下所示,
但是当我尝试tapply()
在 R 中使用函数来转换我的输入数据时,
Sample_Data = read.csv("C:\\Users\\Downloads\\Sample.csv")
OutPut_Table = with(Sample_Data, tapply(Sample_Data$Value,
list(COMPOSE_ID=Sample_Data$Part_ID , PARAMETERS=Sample_Data$Parameters) , tail, 1))
我得到的数据是
您能否帮助我在每组参数列之间添加分层列(Station_ID 和时间)。谢谢