Watts-College / cpp-525-spr-2022

https://watts-college.github.io/cpp-525-spr-2022/
0 stars 0 forks source link

Lab 1 - stuck on data frame #5

Open kaseympotts opened 2 years ago

kaseympotts commented 2 years ago

OK, full disclosure, I've got a case of COVID (thanks, Husbeast) and that's making an already tough-for-me topic more difficult.

I'm trying to set up the initial data frame using two ifelse statements:

Treatment <- ifelse(bus.riders$Time>120,1,0) #create treatment column TimeSince <- ifelse(bus.riders$Time>120,1:245,0) #create Time Since column

But it's making the TimeSince column start numbering at 121, go through 245, then loop.

How do I get it to start counting at 1 in row 121?

(Also thought I posted this several hours ago before I took a nap, but apparently not)

Dselby86 commented 2 years ago

Try

Time.Since <= c(rep(0,130) , 1:245)

There are a bunch of different ways to do this.

On Sat, Mar 19, 2022, 3:20 PM kaseympotts @.***> wrote:

OK, full disclosure, I've got a case of COVID (thanks, Husbeast) and that's making an already tough-for-me topic more difficult.

I'm trying to set up the initial data frame using two ifelse statements:

Treatment <- ifelse(bus.riders$Time>120,1,0) #create treatment column TimeSince <- ifelse(bus.riders$Time>120,1:245,0) #create Time Since column

But it's making the TimeSince column start numbering at 121, go through 245, then loop.

How do I get it to start counting at 1 in row 121?

(Also thought I posted this several hours ago before I took a nap, but apparently not)

— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-525-spr-2022/issues/5, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHBYCMCROOCVGGKFJDYTVAZHKZANCNFSM5RESXY7Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

kaseympotts commented 2 years ago

@Dselby86

So, to make sure I understand WHY: -my initial attempt was simply counting rows, not numbering from a designated start point, and all I did was limit it to 245 before it looped. -this suggestion has it repeat 0 for the specified initial amount, THEN proceed with 1 through 245, correct?

(Trying to make sure I'm learning and not just parroting things.)

Dselby86 commented 2 years ago

For

TimeSince <- ifelse(bus.riders$Time>120,1:245,0)

Each time R is evaluating the ifelse statement it moves the 1:245 vector ahead one.

So When Time = 1 it is either going to return 0 or 1 , so 0 because time is <= 120 When Time = 2 it is either going to return 0 or 2 , so 0 because time is <= 120 When time = 121 it is either going to return 0 or 121, so 121 because time is > 120 When time = 245 it is either going to return 0 or 245, so 245 because time is > 120

When time = 246 the 1:245 vector restarts at 1. The IfElse statement will return 0 or 1, so 1 because time is > 120 and the vector reset to 1.

I hope this helps

On Sun, Mar 20, 2022 at 8:17 AM kaseympotts @.***> wrote:

@Dselby86 https://github.com/Dselby86

So, to make sure I understand WHY: -my initial attempt was simply counting rows, not numbering from a designated start point, and all I did was limit it to 245 before it looped. -this suggestion has it repeat 0 for the specified initial amount, THEN proceed with 1 through 245, correct?

(Trying to make sure I'm learning and not just parroting things.)

— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-525-spr-2022/issues/5#issuecomment-1073272971, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHB5NMGPNR7OJOTGA7L3VA46O3ANCNFSM5RESXY7Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>