[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

[Solved] how to create a dataframe in R from ” Min. 1stQu Median Mean 3rdQu Max. NA’s”? [closed]

One approach is to use the tidy function from the broom package. It is versatile and can organize most R statistical results into a data frame. library(broom) set.seed(1) x <- rnorm(1000) x[sample(1:length(x), 100)] <- NA df <- tidy(summary(x)) df minimum q1 median mean q3 maximum NA’s 1 -3.008 -0.6834 -0.01371 0.00106 0.6978 3.81 100 As … Read more

[Solved] Write a function that returns avg arrival delay by carrier by airport in R

This is what I was looking for avgDelay <- function(carrier, dest) { TempTotal = 0 TempCount = 0 for(i in 1:dim(delays)[1]) { if(delays$CARRIER[i] == carrier & delays$ARR_DELAY[i] >0 & is.na(delays$ARR_DELAY[i]) == FALSE & delays$DEST[i] == dest) { TempTotal <-TempTotal + delays$ARR_DELAY[i] TempCount <-TempCount + 1 # keeps count of the number of delays } } … Read more

[Solved] Cbind Error ” Object not found”

You defined one and only one object when you executed: tino=read.delim(“clipboard”) The column names of that object are not handled as other objects. If you wnated to create a new object from that dataframe you could do this: x <- with(tino, cbind(DEX, GRW , Debt, Life) ) It’s possible this might do violence to the … Read more

[Solved] Calculate gradient of data in R (or other) [closed]

As Gregor points out, you need a more fine-grained representation of your time variable if you want to look at how temperature changes by time. There are two solutions. The best option is if your data are ordered in the order they were recorded (so the first row was the first measurement, second row second … Read more