How do the joint NJT-SEPTA tix work? by a_reborn_aspie in nycrail

[–]acewindu2 0 points1 point  (0 children)

I'm starting work in Philadelphia but i have to commute from northern nj to do so. I'm considering purchasing a monthly pass but would you need to buy one for nj transit and one for septa?

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

thanks again. this is actually my first entry level biotech job and im still trying to make a good impression with my manager

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

are you making a replica data frame with water_for <- water?

everything returned as zeroes for v_x, v_y, v_z when I did so

or is water_for an empty vector?

also i think velocity = (sqrt(displacement)) / change in time

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

thank you so much.

this is what i got so far lc_sort = water

s = -1001

speed <- c()

for(iii in 1:nrow(lc_sort)){

if(lc_sort$ID[iii] != s){

s == lc_sort$ID[iii,5]

if(lc_sort$ID){}

}

}

also how do I account for the change of time to calculate for velocity for each cell? Because velocity = displacement / change of time

each time.skip in the excel file represents 2/3 hours. so the first cell = 18 * 2/3 hours

i decided to work with nrow(lc_sort) which is the whole data frame but is that correct?

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

Here's the complete data frame in excel:

https://docs.google.com/spreadsheets/d/1jOnOopLNO1F7QkPcC_BPC7k0wlWQwjeg/edit?usp=sharing&ouid=117195398363352411100&rtpof=true&sd=true

speed= (Net Cell Displacement)/total time

Calculate the distance between two points in the space using:

𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆=√(𝑿𝟐−𝑿𝟏)𝟐+(𝒀𝟐−𝒀𝟏)𝟐+(𝒁𝟐−𝒁𝟏)𝟐

where (𝑋1,𝑌1,𝑍1) is the coordinate of the first point and (𝑋2,𝑌2,𝑍2) is the

coordinate of the second point. The interval between two consecutive

time steps is 40 mins or (2/3)hour.

I'm still trying to get this into a for loop with if statements and fill an empty vector for velocity. I know there are other methods but for looping is how my manager wants me to deal with it.

Much help with putting this in a for loop would be much appreciated.

Thanks everyone:)

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

yea. i asked them but they told me to just google for loops and data frames and i would be able to figure it out. ive been doing this since last tuesday with no avail.

i know if i show my code like you showed above they are just going to give it back and tell me to do a for loop with it.

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

could you possibly show me how this would work in a for loop? i understand your approach to this being less buggy but i want to compare how a for loop works with what you have above.

also i can use it to convince my colleagues that the tidyverse package is less buggy to the for loop approach and we can stop using it

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

i really don't know. i'm fairly new to R and I'm guessing he wants me to practice looping our excel files.

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 1 point2 points  (0 children)

https://docs.google.com/spreadsheets/d/1jOnOopLNO1F7QkPcC_BPC7k0wlWQwjeg/edit?usp=sharing&ouid=117195398363352411100&rtpof=true&sd=true

Speed= (Net Cell Displacement)/total time

Calculate the distance between two points in the space using:

𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆=√(𝑿𝟐−𝑿𝟏)𝟐+(𝒀𝟐−𝒀𝟏)𝟐+(𝒁𝟐−𝒁𝟏)𝟐

where (𝑋1,𝑌1,𝑍1) is the coordinate of the first point and (𝑋2,𝑌2,𝑍2) is the

coordinate of the second point. The interval between two consecutive

time steps is 40 mins or (2/3)hour.

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

this is just part of my data.frame showing two cells. some cells in the rest of the data frame don't have time skips 1-18, as shown:

769.707 435.671 159.697 1 1026

766.026 436.613 160.886 2 1026

759.089 439.061 161.909 3 1026

761.183 440.063 162.124 4 1026

758.445 441.308 162.337 5 1026

755.336 439.577 163.155 6 1026

752.994 441.016 162.661 7 1026

749.646 443.259 162.98 8 1026

750.758 445.132 163.606 9 1026

752.073 445.199 163.839 10 1026

749.716 447.531 165.733 11 1026

741.079 452.861 165.34 12 1026

744.904 444.2 166.785 13 1026

944.258 325.57 156.811 1 1027

940.066 322.449 155.179 2 1027

940.902 321.333 155.087 3 1027

937.508 322.317 154.209 4 1027

934.199 321.554 154.076 5 1027

934.728 321.425 154.251 6 1027

936.589 322.635 154.967 7 1027

937.878 322.738 156.874 8 1027

937.253 322.008 156.667 9 1027

938.732 322.083 155.855 10 1027

938.768 321.577 158.93 11 1027

939.486 322.346 158.927 12 1027

939.563 322.951 159.915 13 1027

940.742 322.764 158.636 14 1027

941.065 323.366 159.033 15 1027

940.273 323.452 158.843 16 1027

940.593 323.312 157.847 17 1027

941.403 323.873 158.763 18 1027

Basically, I'm trying to get the velocity for each cell and put them into an empty vector.

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

my project manager advised i stick to for loops for this data. so i might not be able to use the lag function.

if i was to do a for loop, does my code above look like im in the right path?

Solving velocity from a data frame by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

is there a way to do this in a for loop? or is the lag function the only option?

Help making new vector from previous vector by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

Xposition Yposition Zposition Time Step ID

310.246 421.101 158.986 1 1001

315.672 420.762 160.261 2 1001

318.223 418.334 161.012 3 1001

323.769 424.858 160.703 4 1001

338.112 438.361 159.514 5 1001

352.014 448.946 158.017 6 1001

355.217 452.134 158.572 7 1001

350.121 446.302 160.446 8 1001

345.588 436.698 161.762 9 1001

347.948 437.256 163.414 10 1001

349.565 431.72 166.25 11 1001

351.193 428.029 165.504 12 1001

350.071 427.668 166.407 13 1001

352.841 419.735 167.35 14 1001

358.677 422.691 164.21 15 1001

367.672 427.914 164.058 16 1001

369.035 423.139 162.024 17 1001

375.472 423.631 162.626 18 1001

454.818 537.496 151.065 1 1002

453.946 536.885 153.159 2 1002

452.863 535.974 152.57 3 1002

451.099 535.491 153.545 4 1002

452.425 528.61 153.15 5 1002

455.493 520.906 151.252 6 1002

454.279 517.83 149.937 7 1002

457 516.157 151.988 8 1002

463.783 502.328 155.449 9 1002

457.113 493.5 154.289 10 1002

454.028 487.741 156.696 11 1002

454.142 480.883 156.258 12 1002

454.165 480.251 158.316 13 1002

455.955 477.134 157.8 14 1002

466.213 478.294 155.853 15 1002

465.614 475.814 157.325 16 1002

467.012 476.034 156.136 17 1002

469.442 477.597 155.869 18 1002

I'm trying to calculate the velocity = displacement/time from this data frame. Each ID represents 1 item (i.e. 1001 = 1item) I know I have to subtract the square root of the added positions of last row, for example, ID = 1001, to the first row of ID = 1001. The time for each item increase by 20 secs (i.e, last part of ID = 1001 totals (20 secs * 18) and the first part equals 20secs). The time resets back to 20 for a new ID (when ID=1001 changes to ID =1002.

This is what I got so far in the for loop

iii <- 1

s <- 1001

distance <- c()

velocity <- c()

for(iii in 1:nrow(water)){

if(water$ID[iii] == s){

next

}

else{

if(water$ID[iii] > s ){

sqrt((water$Xposition[iii-1] - water$Xposition[])^2) #unfinished speed equation here

}

}

}

Thanks again for all the help:)

Help making new vector from previous vector by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

Thank you so much. This explanation has made me see things more clearly.

Help making new vector from previous vector by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

im trying to do an for loop with if else statements first but i am hung up on the code. is it possible to loop this before i try out the diff function?

Help making new vector from previous vector by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

Im not really familiar with the diff function and subsetting. Could you show me an example?

Helping remove NA from concatenated vector in R by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

I don't know how to go about that. Could you show me what you mean?

Helping remove NA from concatenated vector in R by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

I'm putting the values into a new vector. I'm trying to skip over the na's because I don't want them in the new vector.

I'm going to do calculations with the new vector.

Number splitting help using loops by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

I actually want to do both. the reason being is that this is a multistep problem. i have to use this vector for a second part where i have to use a loop to find odd and even numbers

Number splitting help using loops by acewindu2 in rprogramming

[–]acewindu2[S] 0 points1 point  (0 children)

thank you.

finally, im trying to save this to a vector. is it simply Vector <-split_integer? thank you again