I would like to make a modification to my database. What I am trying to do is transform every row of my database being for a single individual.
I want it to look like this. Example:
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
. . . . . .
. . . . . .
Although I found some examples in the forum, I couldn't solve my problem. I will present both attempts. When I execute the code below, I find that it overrides some variables and is not the way you want.
####################################
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")
However, with the example above it is filling one variable below another, how to do it?
There seems to be an unambiguous
"id"
column missing, which you may substitute bycbind
ing the row numbers. Then you could use basereshape
where we grap the values for thetimes
argument from the column names. (Note that you need to add1
to thevarying
s if you setid
as first column as I did.)Result