如何基于R中的if条件语句重新编码一组变量中的负值?

时间:2019-05-30 22:05:07

标签: r function if-statement conditional-statements recode

R新手在这里。我目前正在尝试重新编码R中的一组变量,以便将其中的所有负值都重新编码为正值。

请在下面找到模拟数据:

<androidx.drawerlayout.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorActivityBackground"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:layoutDirection="locale"
        android:orientation="vertical"
        android:textDirection="locale">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/topbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                app:contentInsetEnd="0dp"
                app:contentInsetLeft="0dp"
                app:contentInsetRight="0dp"
                app:contentInsetStart="0dp"/>
        </RelativeLayout>
    </FrameLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:maxWidth="320dp">

        <ExpandableListView
            android:id="@+id/navList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:background="@color/white"
            android:groupIndicator="@null" />

    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>

这是我到目前为止编写的函数:

- hosts: myserver
  become: yes
  tasks:
  - name: pull changes
    shell: chdir=/path/whereis/myrepo git pull https://mygituser:mypassword@bitbucket.org/company/myrepo.git master

尽管我收到以下错误:

df <- data.frame(ID = c(1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011),
                 measure1 = rnorm(11, mean = 0, sd = 1),
                 measure2 = rnorm(11, mean = 0, sd = 1),
                 measure3 = rnorm(11, mean = 0, sd = 1),
                 measure4 = rnorm(11, mean = 0, sd = 1))

关于如何进行这项工作的任何想法?

谢谢!

1 个答案:

答案 0 :(得分:4)

您可以使用

df[, 2:5] <- abs(df[, 2:5])