Peter Dalgaard wrote:
>
>>
>> times = 3:4
>> do.call(rbind, by(data, data$id, function(data)
>> with(data, {
>> rows = (time == times[which(times %in% time)[1]])
>> if (is.na(rows[1])) data.frame(id=id, time=NA, x=NA) else
>> data[rows,] })))
>>
>> # id
Wacek Kusnierczyk wrote:
gallon li wrote:
Suppose I have a long format for a longitudinal data
id time x
1 1 10
1 2 11
1 3 23
1 4 23
2 2 12
2 3 13
2 4 14
3 1 11
3 3 15
3 4 18
3 5 21
4 2 22
4 3 27
4 6 29
I want to select the x values for each ID when time is equal to 3. When that
observation is
gallon li wrote:
> Suppose I have a long format for a longitudinal data
>
> id time x
> 1 1 10
> 1 2 11
> 1 3 23
> 1 4 23
> 2 2 12
> 2 3 13
> 2 4 14
> 3 1 11
> 3 3 15
> 3 4 18
> 3 5 21
> 4 2 22
> 4 3 27
> 4 6 29
>
> I want to select the x values for each ID when time is equal to 3. When that
> obse
e-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of gallon li
Sent: Sunday, 29 March 2009 6:51 PM
To: r-help
Subject: [R] select observations from longitudinal data
Suppose I have a long format for a longitudinal data
id time x
1 1 10
1 2 11
1 3 23
1 4 23
2 2
Suppose I have a long format for a longitudinal data
id time x
1 1 10
1 2 11
1 3 23
1 4 23
2 2 12
2 3 13
2 4 14
3 1 11
3 3 15
3 4 18
3 5 21
4 2 22
4 3 27
4 6 29
I want to select the x values for each ID when time is equal to 3. When that
observation is not observed, then I want to replace it with
Try this. 'by' splits up the data frame into one data frame
per id and then f acts separately on each such sub-dataframe
returning a ts series with NAs for the missings. cbind'ing
those all together gives us this series with one column
per id:
> tt
Time Series:
Start = 1
End = 6
Frequency = 1
one way is the following:
dat <- read.table(textConnection("id time y
1 1 10
1 2 12
1 3 15
1 6 18
2 1 8
2 3 9
2 4 11
2 5 12
3 1 8
3 4 16
4 1 9
4 5 13
5 1 7
5 2 9
5 6 11"), header = TRUE)
closeAllConnections()
val <- 4
dat. <- data.frame(id = unique(dat$id), time = val)
out <- merge(dat, dat., al
I have the following longitudinal data:
id time y
1 1 10
1 2 12
1 3 15
1 6 18
2 1 8
2 3 9
2 4 11
2 5 12
3 1 8
3 4 16
4 1 9
4 5 13
5 1 7
5 2 9
5 6 11
I want to select the observations at time 4. if the observation at time 4 is
missing, then i want to slect the observation at time 3. if the ob
8 matches
Mail list logo