R matrices Code Coach pls help! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

R matrices Code Coach pls help!

Here this one is really hard to me , i tried to get it to work but some or the other gets wrong and I can't fix it pls help me solve Question: Matrix operations are often used in data manipulation and processing. To solve this task, you need to define a matrix with the given number of rows and fill it with the numbers 1 to 10. After that, output the transpose of the resulting matrix. Sample Input 3 Sample Output [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9 [4,] 10 1 2 My code: rows <- readLines('stdin') rows <- as.integer(rows[1]) m <- matrix(c(1:10),nrow = rows) print(t(m))

11th Jun 2022, 3:48 PM
Hrithika Reddy
Hrithika Reddy - avatar
7 Answers
+ 2
rows <- readLines('stdin') rows <- as.integer(rows[1]) m <- matrix(c(1:10),nrow = rows) print(t(m))
12th Jun 2022, 1:45 PM
Hrithika Reddy
Hrithika Reddy - avatar
+ 1
Do you already have some code?
11th Jun 2022, 4:19 PM
Paul
Paul - avatar
+ 1
data <- c(1, 2, 3, 4, 5, 6, 7, 8, 9,10) A <- matrix(data, nrow = 3, ncol = 4) A_T <- t(A) print("transpose of A") print(A_T)
11th Jun 2022, 4:28 PM
Coder Kay
Coder Kay - avatar
+ 1
I had but i dint save the code
11th Jun 2022, 5:33 PM
Hrithika Reddy
Hrithika Reddy - avatar
+ 1
🙂👍
11th Jun 2022, 5:35 PM
Coder Kay
Coder Kay - avatar
+ 1
Finnally I got my to copy paste my code it was not working for some reason , here is my code
12th Jun 2022, 1:46 PM
Hrithika Reddy
Hrithika Reddy - avatar
+ 1
Does it work now? My code looks almost the same, only the third line is different: y <- matrix(1:10, nrow = rows,)
12th Jun 2022, 1:51 PM
Paul
Paul - avatar