Time Series, how can I separate numbers ?

Hi,

I have a data base with 400 numbers. How can I do to work with 200-400 numbers, or just 1-100? I want to study differents parts of my serie and I need to separate sometimes.

Thanks

df <- data.frame(x=runif(400,0,1), y=runif(400, 1, 100)) # data to check code
df1 <- df[c(1:100),]
df2 <- df[c(200:400),]

sorry, this answer didn't help me, changed all my numbers. my time series has 400 numbers, I just want to study the last 200 or the 100 first numbers. When I use y=runif, change everything.

@fcas80 was just making up some data. If you have a variable y, you can use y[1:100]. If you have a dataframe with more than one column, use df[1:100, ]

Hi,

Just posting this as an additional method as you stated you were using a time series, and I personally prefer to extract around dates/datetimes

You can use the dates/times in a filter as below:

library(tidyverse)
library(lubridate)

## example dataframe

df <- tibble(
  date = seq(ymd('2021-01-01'), ymd('2021-12-31'), by = 1),   ## ymd() sets the format of your timesereis
  var_1 = sample(1:100, 365, replace=TRUE),
  var_2 = sample(50:75, 365, replace=TRUE)
  )


## extract using dates

df_extract <- df %>% 
  filter(
    between(date, ymd('2021-05-01'), ymd('2021-05-31'))      ## ensure the filter format matches the format in the df
  )

If your timeseries is a higher resolution, just change the formatting of the times to ymd_hms() (this goes down to seconds). Run ?lubridate for more information on that.

Hope this is useful.

I Will try , but not now, I'm reading a book and studying more; I need to be good with R and time series for financial markets. If you know an exclusive page/blog/anything about R and stock markets, I want to know too.

thanks all

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.