簡體   English   中英

在R中創建一個邏輯向量並使用哪個函數

[英]Create a logical vector in R and use which function

我有一個包含三列的數據集。 第一列是類型,第二列是區域,第三列是值。 我想寫一個邏輯向量,使得type = 1,area = 3和worth = 6.我能夠使用子集創建數據幀,但我無法創建邏輯向量。

hello <- read.csv("type.csv")
hello1 <- subset(hello, type==1 & area ==3 & worth ==6)

值列中有許多NA值。 數據集是https://www.dropbox.com/s/gjjwmnr8uxmy18y/type.csv

謝謝。

Jdbaba

所以問題仍然存在:

which(with(hello, type == 1 & area == 3 & Worth == 6))

請記住,您可以將其用作:

which(hello$type1 == 1 & hello$area == 3 & hello$Worth == 6)

同樣。 但是,當你有更多要檢查的語句時,一個with會派上用場,因為它允許你每次都不用鍵入hello$進行檢查。

雖然答案已被接受,但OP要求創建一個邏輯向量和答案

which(hello$type1 == 1 & hello$area == 3 & hello$Worth == 6)

返回符合這些條件的行。 要改為返回一個邏輯向量,只需使用參數which ,即

hello$type1 == 1 & hello$area == 3 & hello$Worth == 6

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM