我想对我的数据库进行修改。我想要做的是将我的数据库的每一行转换为一个人。
我希望它看起来像这样。例子:
ID massaseca Fator Anexo Teor Tempo
1 334,68 AM c 0 0
1 344,19 AM c 0 10
1 347,32 AM c 0 20
1 350,2 AM c 0 30
1 352,52 AM c 0 40
. . . . . .
. . . . . .
尽管我在论坛中找到了一些示例,但我无法解决我的问题。我将介绍这两种尝试。当我执行下面的代码时,我发现它覆盖了一些变量并且不是你想要的方式。
####################################
require(reshape2)
long <- melt(dados1, id.vars = c("Teor", "Fator"))
melt(dados1, id.vars = 1:2)
melt(dados1, measure.vars = 4:45)
melt(dados1, measure.vars = as.character(10,20,30,
40,50,60,70,80,
90,105,120,135,150,
170,190,210,230,250,
270,290,310,330,350,
360,405,450,510,570,
630,690,750,810,870,
930,990,1050,1110,1170,
1230,1290,1350))
################# CASE 2 ###########
####################################
library(data.table)
long1 <- melt(setDT(dados1), id.vars = c("Teor", "Fator"), variable.name = "Tempo")
long1
melt(setDT(dados1), id.vars = 1:2, variable.name = "Tempo")
melt(setDT(dados1), measure.vars = 4:45, variable.name = "Tempo")
melt(setDT(dados1), measure.vars = as.character(10,20,30,
40,50,60,70,80,
90,105,120,135,150,
170,190,210,230,250,
270,290,310,330,350,
360,405,450,510,570,
630,690,750,810,870,
930,990,1050,1110,1170,
1230,1290,1350), variable.name = "Tempo")
但是,对于上面的示例,它是在另一个变量下方填充一个变量,该怎么做呢?