Try this:
a <- data.frame(timestamp=c(3,5,8),
mylabel=c("abc","def","ghi"))
b <- data.frame(timestamp=c(1:10))
txt <- as.character(a$mylabel)
nrepeat <- diff(c(a$timestamp,nrow(b)))
b$mylabel <- c( rep(NA, a$timestamp[1]), rep(txt,
diff(c(a$timestamp,nrow(b)))) )
greetings,
Remko
-------------------------------------------------
Remko Duursma
Research Lecturer
Centre for Plants and the Environment
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753
Dept of Biological Science
Macquarie University
North Ryde NSW 2109
Australia
Mobile: +61 (0)422 096908
remkoduursma.com
On Wed, Jul 14, 2010 at 3:04 PM, Ralf B <ralf.bierig at gmail.com>
wrote:> I have a set of labels arranged along a timeframe in a. Each label has
> a timestamp and marks a state until the next label. The dataframe a
> contains 5 such timestamps and 5 associated labels. This means, on a
> continious scale between 1-100, there are 5 markers. E.g. 'abc'
marks
> the timestampls between 10 and 19, 'def' marks the timestamps
between
> 20 and 32, and so on.
>
> a <- data.frame(timestamp=c(3,5,8),
mylabel=c("abc","def","ghi"))
> b <- data.frame(timestamp=c(1:10))
>
> I would like to assign these labels as an extra collumn 'label' to
the
> data.frame b which currently only consists of a the timestamp. The
> output would then look like this:
>
> ? ? ? timestamp ? ? ?label
> 1 ? ? 1 ? ? ? ? ? ? ? ? ? ?NA
> 2 ? ? 2 ? ? ? ? ? ? ? ? ? ?NA
> 3 ? ? 3 ? ? ? ? ? ? ? ? ? ?"abc"
> 4 ? ? 4 ? ? ? ? ? ? ? ? ? ?"abc"
> 5 ? ? 5 ? ? ? ? ? ? ? ? ? ?"def"
> 6 ? ? 6 ? ? ? ? ? ? ? ? ? ?"def"
> 7 ? ? 7 ? ? ? ? ? ? ? ? ? ?"def"
> 8 ? ? 8 ? ? ? ? ? ? ? ? ? ?"ghi"
> 9 ? ? 9 ? ? ? ? ? ? ? ? ? ?"ghi"
> 10 ?10 ? ? ? ? ? ? ? ? ? ?"ghi"
>
> What is the simplest way to assign these labels based on timestamps to
> get this output. The real dataset is several millions of rows...
>
> Thanks,
> Ralf
>
> ______________________________________________
> R-help at r-project.org mailing list
> stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>