Hi Thomas,
I suspect part of the reason you did not get a response the first time
is that your example is not very easy to use. You say you have lists
of data frames, but we only have two data frames (which you said
worked fine). dput() is a nice way to provide example data if you
cannot/do not want to use some of the number generators to create a
little example.
In the absence of a full example, the following solution is untested
and makes some assumptions, but hopefully it is enough to get you
going.
1) you said merging two data frames with merge() worked fine
2) attempts at lapply()ing over both lists did not work
so we need to find a way to duplicate merging two data frames.
lapply(seq_along(GPS), function(i) {
merge(GPS[[i]], temp[[i]])
})
rather than going over the list, we will go over an index of the
elements in the lists and use that two merge them element by element.
Of course as I said this makes some assumptions (both lists have equal
lengths, etc.).
Josh
On Mon, Aug 8, 2011 at 9:28 AM, tomtomme <langkamp at tomblog.de>
wrote:> still no answer? I?ll try to be more precise and will ask on stack-overflow
> too...
>
> I?ve got multiple data.frames of gps- and temperature-data within a list.
> One data.frame looks like:
>
> GPS:
>
> ? ? ? ? ? date ? ? time ? ? x.lat ? ? x.lon
> ? ?1 ? ? ?22.05.11 13:50:37 53.57908 10.034599
> ? ?2 ? ? ?22.05.11 13:50:38 53.57906 10.034633
>
> temp:
>
> ? ? ? ? ? ?date ? ? time ? ? temp
> ? ?1 ? ? ?22.05.11 13:50:38 21.6120
> ? ?2 ? ? ?22.05.11 13:50:39 21.6070
>
> So I have two lists, one with multiple gps-data.frames and one with
multiple
> temp-dataframes. I used lapply to manipulate both lists, but can?t merge
> temp and gps to one big list, containing all data.frames, for only
> time-stamps which exists in both list, like for the above example only
> 13:50:38 exists in both:
>
> GPS+temp:
>
> ? ? ? ? ? date ? ? time ? ?x.lat ? ? x.lon ? ? temp
> ? ?1 ? ? ?22.05.11 13:50:38 53.57906 10.034633 21.6070
>
> For the single data-frames that worked just fine with:
>
> ? ?both <- merge(gps,temp)
>
> For the two lists of data.frames I first tried an lapply over both
> lists...something like
>
> ? ?both <- lapply(temp, gps, function(x){x <- merge(x);x})
>
> Then I tried it with
>
> ? ?both <- merge.list(gps,temp)
>
> but this doesn?t work either. It just transfers the first list
"gps" to both
>
> Thanks for any hint, Thomas
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/merging-lists-within-lists-via-time-stamp-tp3712631p3727496.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/