[R] splitting data matrix into submatrices

Avi Gross @v|gro@@ @end|ng |rom ver|zon@net
Thu Jan 6 18:36:55 CET 2022


My apologies. I temporarily used another mailer and I see it did not send my message as plain text. I have not yet seen a way to change on a per message basis. My code, was naturally displayed badly. Sigh.
rows <- 1826

weekends <- (rows %% 7 <= 1)

satsun <- mymat[weekends,]

workweek <- mymat[!weekends,]

Is this any better?


-----Original Message-----
From: Avi Gross via R-help <r-help using r-project.org>
To: r-help using r-project.org <r-help using r-project.org>
Sent: Wed, Jan 5, 2022 12:52 pm
Subject: Re: [R] splitting data matrix into submatrices

Faheem seems to reply to people in private and I replid to him in private but seeing later messages, am giving a synopsis in public.
I too suggesed that using a data.frame is a better way to keep his data and use it for some purposes.
But my understanding is that his matrix is fairly easy to understand and can be indexed given the way it is set up.
Every row of the matrix has info for a single day, with each hour represented by one column. There is no date anywhere in sight or any visible index. But the collection was done starting on a Sunday and continuing without gaps so every seventh following row is a Sunday. So it is trivial to do what he asks using the %% operator to select all numbers between 1 and the number of rows in the matrix that have a remainder of either 0 (Saturdays) or 1 (Sundays) with something like this if the data is in mymat:
rows <- 1826weekends <- (rows %% 7 <= 1)satsun <- mymat[weekends,]
This basically indexes the matrix using a boolean vector. The result can be saved as a matrix of weekend data.
Getting the second matrix is as trivial as flipping the boolean vector.
workweek <- mymat[!weekends,]

-----Original Message-----
From: Faheem Jan <faheemjan93 using yahoo.com>
To: Avi Gross <avigross using verizon.net>
Sent: Tue, Jan 4, 2022 11:44 pm
Subject: Re: [R] splitting data matrix into submatrices

First I will thank you for your interest and time. As my first day is Sunday, in my data matrix 24 are hourly demand of electricity. As electricity demand is different is working and non-working days, so I want a separate analysis for working and nonworking days that's why I want to split the data matrix into submatrices. Can we use for looping which divides the matrix into submatrices? 

    On Wednesday, January 5, 2022, 09:29:44 AM GMT+5, Avi Gross via R-help <r-help using r-project.org> wrote:  
 
 
If you explain better, we can help. But first consider what you are asking and how it is relected in the data.
Is the first component a row number whose meaning is day 1 contains a 1 or perhaps 0 and the next row contains one more? Or is there some kind of date in there?
What day of the week is the first day? Is it a Sunday or a Wednesday or what?
Just for arguments sake, say the first row is a Sunday and all later rows are sequential. Then row 1 is a weekend and row 7 is a weekend and so are rows 7 more (8 and 18) and those 7 more and so on. 
What do you call it when you are looking for the remainder after dividing by 7?
Can you make a list of indices that contain every possible weekend, and another index containing just the non-weekends? 
If other things like Holidays do not matter, you can index the matrix many ways by asking for all columns but only the rows that your logical index wants. 
If I have misunderstood the problem, ignore.

-----Original Message-----
From: Faheem Jan via R-help <r-help using r-project.org>
To: R-help Mailing List <r-help using r-project.org>
Sent: Tue, Jan 4, 2022 10:52 pm
Subject: [R] splitting data matrix into submatrices

I have data in a matrix form of order 1826*24 where 1826 represents the days and 24 hourly observations on each data. My objective is to split the matrix into working (Monday to Friday) and non-working (Saturday and Sunday) submatrices. Can anyone help me that how I will do that splitting using R?


    [[alternative HTML version deleted]]

______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

    [[alternative HTML version deleted]]

______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
  
    [[alternative HTML version deleted]]

______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list