0
votes

I have a time series(a csv file) data that looks like below. Each observation is spaced at interval of 2 seconds :

Group,Id, Observations (illustration only--csv file dont have headers)
A,21,2,3,4
B,12,2,9
C,13,3,5
A,14,4,6,7,9,12,3,4,5,6
B,15,3,5,2,1,3
C,16,8,67
A,27,98,78
B,18,2,3,4,5,6,7,8,1,2,3,4,5
C,19,2,3,4,5,6,6,4,3,3,2,3,4,4,5,6,66,6,4,3,232

Each row is a separate time series data. I am trying to compare and contrast these time series data w.r.t group(A,B,C) with some plots(at least for now).

Edit : I read the csv file as suggested in Import data into R with an unknown number of columns? which would read this csv as

 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21  X22
  A 21  2  3  4 NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
  B 12  2  9 NA NA NA NA NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA  NA
                      ---------------------------
  C 19  2  3  4  5  6  6  4   3   3   2   3   4   4   5   6  66   6   4   3  232

I tried to plot this data with ggplot by melting the data with

melt(data,c("X1","X2")) 
which gives me result
    X1 X2   variable value
1    A 21       X3     2
2    B 12       X3     2
3    C 13       X3     3
4    A 14       X3     4
5    B 15       X3     3
6    C 16       X3     8
7    A 27       X3    98
8    B 18       X3     2
9    C 19       X3     2
10   A 21       X4     3
11   B 12       X4     9
12   C 13       X4     5
13   A 14       X4     6
14   B 15       X4     5
15   C 16       X4    67
----------------------

X3,X4,X5..X22 are observation over period of time. I want to compare different groups(A,B,C) of data by independently plotting each observations(or say create time series for each observation).
I could not figure out plotting solution with zoo package. I was wondering how such plot can be generated for this type of time series data?

1
It appears that you have more data points for group C compared to A and B. How do the extra data points fall in line with the other two groups? How does the second B row compare to the first? Should they be combined into one continuous time series? What was the result of melt(data, ....? Can you provide dput(data) after you read it in? - Chase
Above is just an illustration and number of observations are different for different group. I cannot combine groups(A,B or C) as observations are independent belonging to different groups and different ID and I am interested in observing behavior for each group separately. - iinception
So what is column x2 here? Is this like a subject ID, so you have multiple subjects within groups A, B and C? When you say in your comment to the answer below "Panel A would group all the time series observations belonging to group A", each row of your original data frame is a separate observation which you would like a line for? - nzcoops
yes, each row of my data frame is a separate observation that I want line for - iinception

1 Answers

2
votes

Try this:

Lines <- "A,21,2,3,4
B,12,2,9
C,13,3,5
A,14,4,6,7,9,12,3,4,5,6
B,15,3,5,2,1,3
C,16,8,67
A,27,98,78
B,18,2,3,4,5,6,7,8,1,2,3,4,5
C,19,2,3,4,5,6,6,4,3,3,2,3,4,4,5,6,66,6,4,3,232"

library(zoo)
k <- max(count.fields(textConnection(Lines), sep = ","))
DF <- read.table(textConnection(Lines), sep = ",", fill = TRUE, col.names = 1:k, 
   as.is = TRUE)

# next line may not be needed but won't hurt
DF[[1]] <- gsub(" ", "", DF[[1]])

z <- zooreg(t(DF[-1]), start = 0, deltat = 2)

plot(z, screen = DF[[1]])