R:需要检查两个变量之间的关系

时间:2017-06-07 14:40:56

标签: r

采用像mtcars(但更大)的数据框

我想获得一个观察列表,其中vs == 1的值和am!= 1的值。我不想要滚动一长串的1和0,但是实际得到一个观察列表。我可以写一个循环,但有更多的R&#39方式来回答这个问题吗?

其他信息

我的实际示例是first中的值NA,而Grade中的值NA不是NA。而这似乎不起作用。 x = subset(spreadgrades, first == NA & Grade == NA) 被特别对待吗?

{{1}}

2 个答案:

答案 0 :(得分:2)

使用data.table

library(data.table)
mtcars<-data.table(mtcars)
mtcars[(vs==1 & am!=1),]

     mpg cyl  disp  hp drat    wt  qsec vs am gear carb
1: 21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
2: 18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
3: 24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
4: 22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
5: 19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
6: 17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
7: 21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1

答案 1 :(得分:1)

根据评论和答案,我决定:

{
"apiVersion": "2017-05-10",
        "name": "nestedTemplateRecoveryServices",
        "type": "Microsoft.Resources/deployments",
        "resourceGroup": "[parameters('nestedTemplateRecoveryServicesResourceGroup')]",
        "dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"],
        "properties": {
            "mode": "Incremental",
            "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {},
                "variables": {},
                "resources": [
                        {
                        "name": "[concat(parameters('existingRecoveryServicesVault'), '/', variables('backupFabric'), '/', variables('v2VmContainer'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')), '/', variables('v2Vm'), concat(parameters('existingVirtualMachinesResourceGroup'),';',parameters('existingVirtualMachines')))]",
                        "apiVersion": "2016-06-01",
                        "location": "[resourceGroup().location]",
                        "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
                        "properties": {
                            "protectedItemType": "[variables('v2VmType')]",
                            "policyId": "[resourceId('Microsoft.RecoveryServices/vaults/backupPolicies',parameters('existingRecoveryServicesVault'),parameters('existingBackupPolicy') )]",
                            "sourceResourceId": "[resourceId(subscription().subscriptionId,parameters('existingVirtualMachinesResourceGroup'),'Microsoft.Compute/virtualMachines',parameters('existingVirtualMachines'))]"
                            }
                        }
                    ]
                },
               "parameters": {},
               "outputs": {}
        }
}