I have a dataset output
in R with a the variables V1
,V2
,V3
,V4
. How can I get the number of observations in V4
that area greater than 2000?
Use the length() function to count the number of elements returned by the which() function, as which function returns the elements that are repeated more than once. The length() function in R Language is used to get or set the length of a vector (list) or other objects.
count in R by using base functionalityBy using the dim function, you can count rows and columns at the same time. The table function is a great addition to that that helps to count by categories in a column.
To count the number of cells that have values greater than a particular number, you can use the COUNTIF function. In the generic form of the formula, rng represents a range of cells that contain numbers, and X represents the threshold above which you want to count. In the example shown, the active cell contains this formula:
The SAS code below uses PROC FREQ to count the number of observations per Type. As you can see, PROC FREQ doesn’t only provide the count per group, but also the percentage, the cumulative frequency, and cumulative percentage.
I don't think colSums will give you the right answer since it doesn't counts the number of observations, but only sums the columns' values. I think that this will give you what you want , I hope.
Here, cell range C3:C12 contains the scoring marks of all the students, and we want to test these scores against criteria, greater than 80 marks, in double quotation marks in criterion expression. COUNTIF function counts the number of cells that contain a value greater than 80 and return the output as number as shown below.
Try using logical test and then sum over the values meeting the condition
sum(output$V4 > 2000)
if using a data.frame you could also use:
nrow(output[output$V4>2000, ])
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