dataframe - Multiply a data frame column with a single row in another data frame, R -


One more value to multiply each element of a column with each value in the row of another data.frame What's the way ?

I want to multiply df2 [1,] with df1 [, 1] and df3 dimension 5 lines X 5 column

  df1 & lt; - data.frame (v1 = c (10, 20, 30, 40, 50), v2 = c (5, 10, 15, 20, 25)). Df1 V1 V2 1 10 5 2 20 10 3 30 15 4 40 20 5 50 25 DF 2 & lt; - Data. Frame (Albany = 0.5, Birmingham = 1.0, Tuscany = 1.5, New York = 2, Atlanta = 2.5, Alabama = 3) & gt; Df2 Albany Birmingham Tuscany New York Atlanta Alabama 1 0.5 1 1.5 2 2.5 3   

Each of the output should have a column for each row and five lines of this type:

 < Code> Albany Birmingham Tuscany New York Atlanta Alabama 1 5 10 15 20 25 30 2 10 20 30 40 50 60 3 15 30 45 60 75 90 4 20 40 60 80 100 120 5 25 50 75 100 125 150   

In my real data set, there are 9500 rows in DF1 and DF2 has 210 columns. Therefore, output data frame I want to subscribe the rows of Nero (9500) x nacl (210)

Returns the data.frame of frame. Thus, you need unlist to get the vector:

  df1 [, 1]% *% t (list (Df2 [1,]) # Albany Birmingham Tuscany New York Atlanta Alabama # [1,] 5 10 15 20 25 30 # [2,] 10 20 30 40 50 60 # [3,] 15 30 45 60 75 90 # [ 4,] 20 40 60 80 100 120 # [5,] 25 50 75 100 125 150    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -