Catch integer 0 in R

0 votes

Consider a statement that produces integer(0)

For example:

 a <- which(1:3 == 5)

Which is the safest way of catching this?

Apr 27, 2018 in Data Analytics by DataKing99
• 8,240 points
2,426 views

1 answer to this question.

0 votes

R's way of printing a zero length vector(an integer one). So you could test for length 0

length(a)
[1] 0

I suggest you not to use which, and try using the above method

It might be worth rethinking the strategy you are using to identify which elements you want, but without further specific details it is difficult to suggest an alternative strategy.

answered Apr 27, 2018 by kappa3010
• 2,090 points

Related Questions In Data Analytics

+1 vote
1 answer

Try catch in R

The most straightforward way is to wrap ...READ MORE

answered Nov 6, 2018 in Data Analytics by Kalgi
• 52,290 points
137 views
0 votes
1 answer

How do I check and catch errors in R

With tryCatch you can handle errors as you want: an.error.occured ...READ MORE

answered Nov 6, 2018 in Data Analytics by Kalgi
• 52,290 points
99 views
0 votes
1 answer

Error sayimg "Executing test function test.should_error ... Timing stopped at: 0 0 0 " in R

In your testthat tests you declare an anonymous function like so: function() ...READ MORE

answered Nov 12, 2018 in Data Analytics by Maverick
• 10,840 points
160 views
+4 votes
0 answers

R programming Error: Error in if (d >= 0) { : missing value where TRUE/FALSE needed

Here is my code: for(i in 1:(nrow(moon_sub))){   l_df[i,] <- ...READ MORE

Jun 23, 2020 in Data Analytics by Molly
• 160 points
269 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 17, 2017 in Data Analytics by Sudhir
• 1,610 points
252 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,620 points
299 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,620 points
2,950 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,620 points
341 views
0 votes
1 answer
0 votes
1 answer

How to join two tables (tibbles) by *list* columns in R

You can use the hash from digest ...READ MORE

answered Apr 5, 2018 in Data Analytics by kappa3010
• 2,090 points
454 views