krutogm.blogg.se

For loop matrix r
For loop matrix r









for loop matrix r

Alternatively, I have set them to -0.01, which still has not changed the outcome of my for-loop. Missing values in this example are represented as NA, and should not be included in the calculation. Note: The structure of these data are only relevant in so far that differences can be calculated for individuals across rows and columns. Is there a way that can calculate the differences I outlined above, and is also more efficient than a nested for-loop? # number of vectors that are not NA, not the values below by time_threshold (2.000). # Dividing by 2 and rounding has proven that this code only counts the # the threshold up for those user-comparisons. # and inter-user time differences, adding values below # Use a nested for-loop to calculate the intra-user Matrix_a<-matrix(nrow = nrow(clean_data), ncol = nrow(clean_data))

for loop matrix r

# Create an empty matrix the same dimensions as the number of users present. I have tried using the following nested for-loop, however I believe it is only counting the number of elements in my matrix instead of adding the differences. Each of User 1's measurements were subtracted iteratively from User 2's measurements (stored as an absolute value), and those differences that were below a value of 2 were considered a "match." Within a threshold of 2.0 units, I have tried to measure each user's time against their own time and other users by obtaining the difference with a nested for-loop.īelow is an example of what the clean_data matrix looks like, and this matrix was used for all three goals: M1 M2 M3 M4įor Goal #3, the output should look something akin to this matrix: U1 U2 U3 U4 U5įor example: User 1 has 2 matches with themselves because, with all 4 of their time measurements, 2 differences were less than a value of 2.0 units.

  • To create a final matrix that counts the number of "matches" (comparisons) each user has against themselves and others.
  • To subtract the user's time from other user's time points (all included, across rows).
  • for loop matrix r

    To subtract the user's time from their own times (across columns).The goals I want to accomplish with this matrix are three fold: Some users only have one measurement of time, while others may have the full 4 measurements.

    for loop matrix r

    Each row represents a user, and each column a measurement of time. I have a matrix that is 10 rows by 4 columns.











    For loop matrix r