Download Package `expss`

Document related concepts

Time series wikipedia , lookup

Transcript
14
count_if
count_if(gt(55), df1$b) # greater than 55 = 2
count_if(ne(75), df1$b) # not equal 75 = 3
count_if(ge(32), df1$b) # greater than or equal 32 = 4
count_if(gt(32) & lt(86), df1$b) # 2
# count only integer values between 33 and 85
count_if(33:85, df1$b) # 2
# values with letters
count_if(regex("^[A-z]+$"), df1) # 4
# values that started on 'a'
count_if(regex("^a"), df1) # 2
# count_row_if
count_row_if(regex("^a"), df1) # c(1,0,0,1)
df1 %row_in% 'apples'
# c(TRUE,FALSE,FALSE,TRUE)
# Some of Microsoft Excel examples for SUMIF/AVERAGEIF/etc
dfs = read.csv(
text = "
property_value,commission,data
100000,7000,250000
200000,14000,
300000,21000,
400000,28000,"
)
# Sum of commision for property value greater than 160000
with(dfs, sum_if(gt(160000), property_value, data = commission)) # 63000
# Sum of property value greater than 160000
with(dfs, sum_if(gt(160000), property_value)) # 900000
# Sum of commision for property value equals to 300000
with(dfs, sum_if(300000, property_value, data = commission)) # 21000
# Sum of commision for property value greater than first value of data
with(dfs, sum_if(gt(data[1]), property_value, data = commission)) # 49000
dfs = data.frame(
category = c("Vegetables", "Vegetables", "Fruits", "", "Vegetables", "Fruits"),
food = c("Tomatoes", "Celery", "Oranges", "Butter", "Carrots", "Apples"),
sales = c(2300, 5500, 800, 400, 4200, 1200),
stringsAsFactors = FALSE
)
# Sum of sales for Fruits