If_na(sheet1) = 5 # replace NA # custom apply apply_col_if( prod, gt( 2 ), sheet1$V1, data = sheet1) # product of all elements by columns apply_row_if( prod, gt( 2 ), sheet1$V1, data = sheet1) # product of all elements by rows # Examples borrowed from Microsoft Excel help for COUNTIF sheet1 = text_to_columns(Ĭount_if( "apples", sheet1$a) # 2 count_if( "apples", sheet1) # 2 with(sheet1, count_if( "apples", a, b)) # 2 count_if(gt( 55 ), sheet1$b) # greater than 55 = 2 count_if(ne( 75 ), sheet1$b) # not equal 75 = 3 count_if(ge( 32 ), sheet1$b) # greater than or equal 32 = 4 count_if(gt( 32 ) & lt( 86 ), sheet1$b) # 2 # count only integer values between 33 and 85 count_if( 33 : 85, sheet1$b) # 2 # values with letters count_if(regex( "^+$" ), sheet1) # 4 # values that started on 'a' count_if(regex( "^a" ), sheet1) # 2 # count_row_if count_row_if(regex( "^a" ), sheet1) # c(1,0,0,1) sheet1 %row_in% 'apples' # c(TRUE,FALSE,FALSE,TRUE) # Some of Microsoft Excel examples for SUMIF/AVERAGEIF/etc sheet1 = text_to_columns( Mean_row_if( 6, sheet1$V1, data = sheet1) # are there any 5 in each row? has_five = cbind(V1, V2, V3) %row_in% 5 ) # count not-NA not_na = count_row_if(not_na, V1, V2, V3), # count NA na = count_row_if( is.na, V1, V2, V3), # count values between 5 and 8 range = count_row_if( 5 %thru% 8, V1, V2, V3), # count integer values between 5 and 8, e. # count values greater than 8 greater = count_row_if(gt( 8 ), V1, V2, V3), # count 8 exact = count_row_if( 8, V1, V2, V3), There is asymmetrical behavior in *_row_ifĪnd *_col_if for function criterion: in both cases function criterion This function will be applied to each column of supplied data and NA's before calculations (as na.rm = TRUE in base R functions).įunction criterion should return logical vector of same size and shape as itsĪrgument. gt(5) is equivalent ">5" in spreadsheet) - seeĬount* and %in*% never returns NA's. There are some special functions forĬonvenience (e. which equal to theĮlements of vector in the criteria will be used as function funįunction Values for which function gives TRUE will be used asįunction fun argument. If omitted then function will be applied onĬustom function that will be applied based on criterion. Doesn't applicable toĬount_*_if functions. Vector, matrix,ĭata on which function will be applied. %has% is an alias forĭata on which criterion will be applied. Presence of criterion in each row/column. %row_in%/ %col_in% return logical vector - indicator of *_col_if returns vector for each column of supplied arguments. *_row_if returns vector for each row of supplied arguments. *_if return single value (vector of length 1). , data = NULL)Īpply_col_if(fun, criterion. , data = NULL)Īpply_row_if(fun, criterion. ThereĪre different flavors of these functions: *_if work on entireĭataset/matrix/vector, *_row_if works on each row and *_col_if on values that meet aĬriterion that you specify. These functions calculate count/sum/average/etc. Count_if: Count/sum/average/other functions on values that meet a criterion Description
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |