Multiplying Vectors in R

  • Comments posted to this topic are about the item Multiplying Vectors in R

  • I believe that the line j <- (4,5) is missing a 'c'. As written the answer should be Error: unexpected ',' in "j <- (4,". Good question though. Thank you Steve.

  • Thanks, good catch. You are correct.

    this is fixed.

  • In addition to the missing 'c' on second vector, error will be thrown on matrix multiplication due to second vector being 1 element shorter than the first. Add 1 to end of second vector. Result 4 10 3.

  • Not an error. A warning. This still works:

    > i <- c(1,2,3)
    > j <- c(4,5)
    > k <- i * j
    Warning message:
    In i * j : longer object length is not a multiple of shorter object length
    > k
    [1] 4 10 12
  • i <- c(1,2,3)

    > j <- c(4,5)

    > k <- i * j

    Warning message:

    In i * j : longer object length is not a multiple of shorter object length

    > k

    [1] 4 10 12

    >

    I stand corrected, my apologies.

    Saw the warning: (my brain registered Error), and did not display the k value.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply