如何比较R中的时间戳?

时间:2016-10-04 20:58:40

标签: r datetime lubridate

我有数据框A

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/vDrawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/vCoordinator"
        style="@style/Layout.Coordinator"
        tools:context="io.stepuplabs.settleup.ui.main.MainActivity">

        <io.stepuplabs.settleup.ui.main.StateAwareAppBar
            android:id="@+id/vAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/vCollapsingToolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorAccent"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed|exitUntilCollapsed|snap">

                <ImageView
                    android:id="@+id/vPlaceholderCircles"
                    android:layout_width="match_parent"
                    android:layout_height="296dp"
                    android:contentDescription="@string/desc_circles"
                    android:scaleType="centerCrop"
                    android:src="@drawable/placeholder"
                    app:layout_collapseMode="none"
                    />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/vToolbar"
                    style="@style/Layout.Toolbar"
                    android:layout_marginBottom="40dp"
                    app:layout_collapseMode="pin"
                    app:layout_collapseParallaxMultiplier="1"
                    app:popupTheme="@style/AppTheme.PopupOverlay">

                    <TextView
                        android:id="@+id/vWhoShouldPayTitle"
                        android:layout_width="wrap_content"
                        android:visibility="gone"
                        android:layout_height="wrap_content"
                        android:layout_gravity="start"
                        android:text="@string/app_name"
                        android:textAppearance="@style/Text.Toolbar" />
                </android.support.v7.widget.Toolbar>

                <android.support.design.widget.TabLayout
                    android:id="@+id/vTabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0"
                    app:tabIndicatorColor="@color/white"
                    app:tabMode="scrollable" />

            </android.support.design.widget.CollapsingToolbarLayout>

        </io.stepuplabs.settleup.ui.main.StateAwareAppBar>

        <android.support.v4.view.ViewPager
            android:id="@+id/vViewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <android.support.v4.widget.ContentLoadingProgressBar
            android:id="@+id/vActivityProgress"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />

        <com.github.clans.fab.FloatingActionMenu
            android:id="@+id/vFloatingActionMenu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom|end"
            android:contentDescription="@string/expense"
            android:paddingBottom="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            app:layout_behavior="io.stepuplabs.settleup.ui.common.FloatingActionMenuBehavior"
            fab:menu_animationDelayPerItem="0"
            fab:menu_backgroundColor="@color/dim"
            fab:menu_buttonSpacing="6dp"
            fab:menu_fab_label="@string/expense"
            fab:menu_icon="@drawable/fab_add"
            fab:menu_labels_cornerRadius="30dp"
            fab:menu_labels_ellipsize="end"
            fab:menu_labels_paddingBottom="8dp"
            fab:menu_labels_paddingLeft="16dp"
            fab:menu_labels_paddingRight="16dp"
            fab:menu_labels_paddingTop="8dp"
            fab:menu_labels_position="left"
            fab:menu_labels_textColor="@color/white"
            fab:menu_labels_textSize="14sp">

            <com.github.clans.fab.FloatingActionButton
                android:id="@+id/vFabTransfer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|end"
                android:contentDescription="@string/transfer"
                android:src="@drawable/ic_transfer"
                fab:fab_label="@string/transfer"
                fab:fab_size="mini" />
        </com.github.clans.fab.FloatingActionMenu>

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/vNavigationDrawer"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/white"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/drawer_header"
        app:itemBackground="@drawable/selector_items_background_color"
        app:itemIconTint="@color/selector_drawer_items_foreground_color"
        app:itemTextColor="@color/selector_drawer_items_foreground_color"
        app:menu="@menu/drawer" />

</android.support.v4.widget.DrawerLayout>

另一个带时间戳的数据框B

structure(list(gauge = c(1094000L, 1094000L, 1094000L, 1100600L
), start = structure(c(2L, 4L, 1L, 3L), .Label = c("4/16/2007 18:45", 
"4/2/2004 12:45", "4/24/2012 9:15", "5/14/2006 21:00"), class = "factor")), .Names = c("gauge", 
"start"), row.names = c(NA, 4L), class = "data.frame")

我想

  1. 从A
  2. 中读取时间
  3. 在B中找到确切的时间及其行号
  4. 在B
  5. 中查找相应的Precip值

    使用lubridate,我将A中的时间戳转换为UTC:

        structure(list(Time = structure(1:20, .Label = c("2002-01-01 00:00", 
    "2002-01-01 00:05", "2002-01-01 00:10", "2002-01-01 00:15", "2002-01-01 00:20", 
    "2002-01-01 00:25", "2002-01-01 00:30", "2002-01-01 00:35", "2002-01-01 00:40", 
    "2002-01-01 00:45", "2002-01-01 00:50", "2002-01-01 00:55", "2002-01-01 01:00", 
    "2002-01-01 01:05", "2002-01-01 01:10", "2002-01-01 01:15", "2002-01-01 01:20", 
    "2002-01-01 01:25", "2002-01-01 01:30", "2002-01-01 01:35"), class = "factor"), 
        Precip.mm.h..1. = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 0)), .Names = c("Time", "Precip.mm.h..1."
    ), row.names = c(NA, 20L), class = "data.frame")
    

    但我不确定如何比较两个时间戳。

    P.S。 B是一个包含一百万行的非常大的文件。所以我无法为你提供A的相应数据。

0 个答案:

没有答案