[Solved] ggplot2 confusion

There is nothing wrong that I can see. Your code works. Some times such errors arise due to not flowing the ggplot expression properly. Try it like this: ggplot(train, aes(x= Item_Visibility, y = Item_Outlet_Sales)) + geom_point(size = 2.5, color=”navy”) + xlab(“Item Visibility”) + ylab(“Item Outlet Sales”) + ggtitle(“Item Visibility vs Item Outlet Sales”) Assuming you … Read more

[Solved] Is is.subset not working in R?

apriori returns rules object, not a vector: data(“Adult”) ## Mine association rules. rules <- apriori(Adult, parameter = list(supp = 0.5, conf = 0.9, target = “rules”)) class(rules) # [1] “rules” if you want to compare lists of rules you will need to transform this object to a data.frame, e.g.: rules.df <- as(rules, “data.frame”) is.subset(rules.df$rules, rules.df$rules) … Read more

[Solved] Calculate variable based on criteria in r

Plyr solution: library(plyr) ddply(df,.(ID),transform,AGE_HEAD=head(AGE,1)) OR ddply(df,.(ID),transform,AGE_HEAD=AGE[PERNO==1]) ID AGE PERNO AGE_HEAD 1 1 30 1 30 2 1 25 2 30 3 2 25 1 25 4 2 24 2 25 5 2 3 3 25 6 3 65 1 65 7 3 55 2 65 data.table solution: library(data.table) DT<-data.table(df) DT[, AGE_HEAD := AGE[PERNO==1], by=”ID”] ID … Read more

[Solved] Make a cumulative plot of events in R

A possible solution: library(lubridate) # example time data time = c( “2015-10-05 15:44:41.986797”, “2015-10-05 15:59:23.389583”, “2015-10-05 16:59:44.99402”, “2015-10-05 16:59:44.99402”, “2015-10-05 16:59:44.99402”, “2015-10-05 16:59:44.99402”, “2015-10-05 17:59:59.594524”, “2015-10-05 17:59:59.594524”, “2015-10-05 18:00:05.555564” ) # transform time strings to POSIXct objects for count time <- ymd_hms(time) # count by second event <- data.frame(table(time)) # transform time factors to POSIXct … Read more