r

ARIMA forecast keep getting error 'data' must be of a vector type, was 'NULL'

时光怂恿深爱的人放手 提交于 2021-02-19 05:01:25
问题 I keep getting an error when fitting my ARIMA to the data, 'data' must be of a vector type, was 'NULL'. library(forecast) foo <- read.csv("https://nofile.io/g/0qrJl41nhf3bQQFjBmM6JurzGJFQSioCTGEzZhWVl9zA1kXnAJsCsSsxN1ZN7F4D/data.csv/") data <- data.frame(year, Car) data <- ts(data[,2],start = c(1990,1),frequency = 1) plot(data) plot(diff(data),ylab='Differenced Car Usage') plot(log10(data),ylab='Log (Car Usage)') plot(diff(log10(data)),ylab='Differenced Log (Tractor Sales)') par(mfrow = c(1,2

How to let print() pass arguments to a user defined print method in R?

笑着哭i 提交于 2021-02-19 04:42:52
问题 I have defined an S3 class in R that needs its own print method. When I create a list of these objects and print it, R uses my print method for each element of the list, as it should. I would like to have some control over how much the print method actually shows. Therefore, the print method for my class takes a few additional arguments. However, I have not found a way to make use of these arguments, when printing a list of objects. To make this more clear, I give an example. The following

p-value from fisher.test() does not match phyper()

感情迁移 提交于 2021-02-19 04:42:16
问题 The Fisher's Exact Test is related to the hypergeometric distribution, and I would expect that these two commands would return identical pvalues. Can anyone explain what I'm doing wrong that they do not match? #data (variable names chosen to match dhyper() argument names) x = 14 m = 20 n = 41047 k = 40 #Fisher test, alternative = 'greater' (fisher.test(matrix(c(x, m-x, k-x, n-(k-x)),2,2), alternative='greater'))$p.value #returns 2.01804e-39 #geometric distribution, lower.tail = F, i.e. P[X >

p-value from fisher.test() does not match phyper()

流过昼夜 提交于 2021-02-19 04:42:05
问题 The Fisher's Exact Test is related to the hypergeometric distribution, and I would expect that these two commands would return identical pvalues. Can anyone explain what I'm doing wrong that they do not match? #data (variable names chosen to match dhyper() argument names) x = 14 m = 20 n = 41047 k = 40 #Fisher test, alternative = 'greater' (fisher.test(matrix(c(x, m-x, k-x, n-(k-x)),2,2), alternative='greater'))$p.value #returns 2.01804e-39 #geometric distribution, lower.tail = F, i.e. P[X >

How do I build an object with the R vctrs package that can combine with c()

廉价感情. 提交于 2021-02-19 04:30:10
问题 I'm trying to understand how to build objects with vectors. I thought this was straightforwards, but then had trouble when I used c() on my object. Our object has two attributes, x and descriptor, both strings in this case (my object will have attributes with differing types). We've built a constructor, new_toy_vector. I haven't built a convenience function in this example yet. new_toy_vector <- function( x = character(), descriptor = character()) { vctrs::vec_assert(x,character()) vctrs::vec

R dplyr. Filter a dataframe that contains a column of numeric vectors

丶灬走出姿态 提交于 2021-02-19 04:22:07
问题 I have a dataframe in which one column contains numeric vectors. I want to filter rows based on a condition involving that column. This is a simplified example. df <- data.frame(id = LETTERS[1:3], name=c("Alice", "Bob", "Carol")) mylist=list(c(1,2,3), c(4,5), c(1,3,4)) df$numvecs <- mylist df # id name numvecs # 1 A Alice 1, 2, 3 # 2 B Bob 4, 5 # 3 C Carol 1, 3, 4 I can use something like mapply e.g. mapply(function(x,y) x=="B" & 4 %in% y, df$id, df$numvecs) which correctly returns TRUE for

How to execute git-bash command with system() or shell() in R

别说谁变了你拦得住时间么 提交于 2021-02-19 04:19:39
问题 I would like to run some command in git-bash shell via system() or shell() functions in R. I am on windows and the default shell is the command prompt. Is there any way I can switch the shell in system() to git-bash ? Thank you 回答1: If your %PATH% includes C:\Program Files (x86)\Git\bin\ , you should be able to system call: bash --login -i -c "your command" The OP JdeMello confirms in the comments: Yup: Didn't have C:\Program Files\Git\bin in PATH . For completion, we can add Git\bin to PATH

Merge two data frames considering a range match between key columns

烂漫一生 提交于 2021-02-19 04:18:59
问题 I am a beginner in programming in R. I am at the moment trying to retrieve some site names from a dataframe containing the X and Y coordinates and site names and copy them into a different dataframe with specific points. FD <- matrix(data =c(rep(1, 500), rep(0, 500), rnorm(1000, mean = 550000, sd=4000), rnorm(1000, mean = 6350000, sd=20000), rep(NA, 1000)), ncol = 4, nrow = 1000, byrow = FALSE) colnames(FD) <- c('Survival', 'X', 'Y', 'Site') FD <- as.data.frame(FD) shpxt <- matrix(c(526654.7

Identify significant change on a slope

孤者浪人 提交于 2021-02-19 04:17:43
问题 I am trying to find a point where a big change happens on a slope. Tried to use ecp::e.divisive() function with different settings and couldn't make it identify the change the way I need. Below code and plot should illustrate more. Grey lines are cutoffs coming from ecp package, and I am trying to it to plot blue line (which is at the moment plotted manually). Please advise if there are better packages for this task. library("ecp") #get cutoff points ecpOutput <- e.divisive(x, k=1) ecpOutput

Identify significant change on a slope

狂风中的少年 提交于 2021-02-19 04:17:02
问题 I am trying to find a point where a big change happens on a slope. Tried to use ecp::e.divisive() function with different settings and couldn't make it identify the change the way I need. Below code and plot should illustrate more. Grey lines are cutoffs coming from ecp package, and I am trying to it to plot blue line (which is at the moment plotted manually). Please advise if there are better packages for this task. library("ecp") #get cutoff points ecpOutput <- e.divisive(x, k=1) ecpOutput