I have a dataset with three columns. The first column is type, second column is area and third column is worth. I want to write a logical vector such that the type =1 , area = 3 and worth = 6. I was able to create the data frame using subset but I couldn't create a logical vector.
hello <- read.csv("type.csv")
hello1 <- subset(hello, type==1 & area ==3 & worth ==6)
There are many NA values in worth column. The data set is https://www.dropbox.com/s/gjjwmnr8uxmy18y/type.csv
Thanks.
Jdbaba
A logical vector is a vector that only contains TRUE and FALSE values. In R, true values are designated with TRUE, and false values with FALSE. When you index a vector with a logical vector, R will return values of the vector for which the indexing vector is TRUE.
logical() function in R Language is used to check whether a value is logical or not. Syntax: is.logical(x) Parameters: x: Value to be checked.
So the question remains answered:
which(with(hello, type == 1 & area == 3 & Worth == 6))
Remember, you can just use it as:
which(hello$type1 == 1 & hello$area == 3 & hello$Worth == 6)
as well. However, when you have more statements to check for, a with
comes in handy as it allows you to check without typing hello$
every time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With