Error saying "Error in lag(x, 1) : unused argument (1)"

0 votes

I need to refer to lagged and lead values of variables but I cannot seem to get the code for the lag function working as documented.

> library(dplyr)
> x <- seq(100,500,100)
> x
[1] 100 200 300 400 500
> lead(x,1)
[1] 200 300 400 500  NA
> lag(x,1)
Error in lag(x, 1) : unused argument (1)
> 
Nov 16, 2018 in Data Analytics by Ali
• 10,380 points
39 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

lag only works as expected with time-series objects. For instance:

cbind(x = ts(1:10), y = lag(1:10, -1))

In your case:

lag_n <- function(x, n) {c(rep(NA, n), x)[1:length(x)])
answered Nov 16, 2018 by Maverick
• 10,020 points

Related Questions In Data Analytics

0 votes
1 answer

Error saying "Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ"

Make sure is a factor time <- as.factor(c("pm", ...READ MORE

answered Nov 9, 2018 in Data Analytics by Maverick
• 10,020 points
526 views
0 votes
1 answer

Error saying "Error in x$children[[1]] : subscript out of bounds" while web scrapping

You could try the httr library: library(XML) library(httr) url <- 'http://www.sainsburys.co.uk/shop/gb/groceries/fruit-veg/all-fruit#langId=44&storeId=10151&catalogId=10122&categoryId=12545&parent_category_rn=12518&top_category=12518&pageSize=30&orderBy=FAVOURITES_FIRST&searchTerm' doc <- ...READ MORE

answered Nov 9, 2018 in Data Analytics by Maverick
• 10,020 points
81 views
0 votes
1 answer

Error saying " ERROR: unused argument (InformationCriterion = InformationCriterion[j]) "

Brief invoke REBMIX as : REBMIX[[i, j, k]] ...READ MORE

answered Nov 9, 2018 in Data Analytics by Maverick
• 10,020 points
30 views
0 votes
1 answer
0 votes
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,020 points
239 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,020 points
22 views
0 votes
1 answer

Error saying "Error in df$item : object of type 'closure' is not subsettable" when trying to use arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,020 points
65 views
0 votes
1 answer

Error saying "Error in rnorm() : argument "n" is missing, with no default" in R

Hey @ali, rnorm() function requires an argument, ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,020 points
110 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.