R语言，如何根据row的index提取矩阵？谢谢指导！

[,1] [,2] [,3] [,4] [,5]
[1,] 1 21 41 61 81
[2,] 2 22 42 62 82
[3,] 3 23 43 63 83
[4,] 4 24 44 64 84
[5,] 5 25 45 65 85
[6,] 6 26 46 66 86
[7,] 7 27 47 67 87
[8,] 8 28 48 68 88
[9,] 9 29 49 69 89
[10,] 10 30 50 70 90
[11,] 11 31 51 71 91
[12,] 12 32 52 72 92
[13,] 13 33 53 73 93
[14,] 14 34 54 74 94
[15,] 15 35 55 75 95
[16,] 16 36 56 76 96
[17,] 17 37 57 77 97
[18,] 18 38 58 78 98
[19,] 19 39 59 79 99
[20,] 20 40 60 80 100

1.根据条件2从矩阵中提取对应行，并构成新矩阵
2.另一个新矩阵恰好不包含条件2中的那些行索引
（可不可以附一下下代码。。。）

1个回答

``````#1.得到对应index的行
targetmatrix[targetindex,]
#2.除去对应index的行
targetmatrix[-targetindex,]
``````
G木木夕 OK了，多谢！

R语言，如何根据row的index提取矩阵？

r语言矩阵+1什么意思？

m <- matrix( c(0,1,5, 0,2,4, 0,3,3, 1,5,3, 1,4,5, 2,5,3, 2,6,2, 3,6,2, 4,1,5, 4,7,4, 5,7,3, 6,7,5) + 1,ncol = 3,byrow = T R语言矩阵中的+1是什么意思

Problem Description Give you a matrix(only contains 0 or 1),every time you can select a row or a column and delete all the '1' in this row or this column . Your task is to give out the minimum times of deleting all the '1' in the matrix. Input There are several test cases. The first line contains two integers n,m(1<=n,m<=100), n is the number of rows of the given matrix and m is the number of columns of the given matrix. The next n lines describe the matrix:each line contains m integer, which may be either ‘1’ or ‘0’. n=0 indicate the end of input. Output For each of the test cases, in the order given in the input, print one line containing the minimum times of deleting all the '1' in the matrix. Sample Input 3 3 0 0 0 1 0 1 0 1 0 0 Sample Output 2

bootstrapTable计算行(Row)的总金额！！在线等！

Problem Description There is a matrix M that has n rows and m columns (1≤n≤1000,1≤m≤1000).Then we perform q(1≤q≤100,000) operations: 1 x y: Swap row x and row y (1≤x,y≤n); 2 x y: Swap column x and column y (1≤x,y≤m); 3 x y: Add y to all elements in row x (1≤x≤n,1≤y≤10,000); 4 x y: Add y to all elements in column x (1≤x≤m,1≤y≤10,000); Input There are multiple test cases. The first line of input contains an integer T(1≤T≤20) indicating the number of test cases. For each test case: The first line contains three integers n, m and q. The following n lines describe the matrix M.(1≤Mi,j≤10,000) for all (1≤i≤n,1≤j≤m). The following q lines contains three integers a(1≤a≤4), x and y. Output For each test case, output the matrix M after all q operations. Sample Input 2 3 4 2 1 2 3 4 2 3 4 5 3 4 5 6 1 1 2 3 1 10 2 2 2 1 10 10 1 1 1 2 2 1 2 Sample Output 12 13 14 15 1 2 3 4 3 4 5 6 1 10 10 1

Problem Description At 17:00, special agent Jack starts to escape from the enemy camp. There is a cliff in between the camp and the nearest safety zone. Jack has to climb the almost vertical cliff by stepping his feet on the blocks that cover the cliff. The cliff has slippery blocks where Jack has to spend time to take each step. He also has to bypass some blocks that are too loose to support his weight. Your mission is to write a program that calculates the minimum time to complete climbing. Figure D-1 shows an example of cliff data that you will receive. The cliff is covered with square blocks. Jack starts cliff climbing from the ground under the cliff, by stepping his left or right foot on one of the blocks marked with 'S' at the bottom row. The numbers on the blocks are the "slippery levels". It takes t time units for him to safely put his foot on a block marked with t, where 1 ≤ t ≤ 9. He cannot put his feet on blocks marked with 'X'. He completes the climbing when he puts either of his feet on one of the blocks marked with 'T' at the top row. Figure D-1: Example of Cliff Data Jack's movement must meet the following constraints. After putting his left (or right) foot on a block, he can only move his right (or left, respectively) foot. His left foot position (lx, ly) and his right foot position (rx, ry) should satisfy lx < rx and | lx - rx | + | ly - ry | ≤ 3. This implies that, given a position of his left foot in Figure D-2 (a), he has to place his right foot on one of the nine blocks marked with blue color. Similarly, given a position of his right foot in Figure D-2 (b), he has to place his left foot on one of the nine blocks marked with blue color. Figure D-2: Possible Placements of Feet Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows: w h s(1,1) ... s(1,w) s(2,1) ... s(2,w) ... s(h,1) ... s(h,w) The integers w and h are the width and the height of the matrix data of the cliff. You may assume 2 ≤ w ≤ 30 and 5 ≤ h ≤ 60. Each of the following h lines consists of w characters delimited by a space. The character s(y, x) represents the state of the block at position (x, y) as follows: * 'S': Jack can start cliff climbing from this block. * 'T': Jack finishes climbing when he reaches this block. * 'X': Jack cannot put his feet on this block. * '1' - '9' (= t): Jack has to spend t time units to put either of his feet on this block. 　 You can assume that it takes no time to put a foot on a block marked with 'S' or 'T'. Output For each dataset, print a line only having a decimal integer indicating the minimum time required for the cliff climbing, when Jack can complete it. Otherwise, print a line only having "-1" for the dataset. Each line should not have any characters other than these numbers. Sample Input 6 6 4 4 X X T T 4 7 8 2 X 7 3 X X X 1 8 1 2 X X X 6 1 1 2 4 4 7 S S 2 3 X X 2 10 T 1 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 2 10 T X 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 10 10 T T T T T T T T T T X 2 X X X X X 3 4 X 9 8 9 X X X 2 9 X 9 7 7 X 7 3 X X 8 9 X 8 9 9 9 6 3 X 5 X 5 8 9 9 9 6 X X 5 X 5 8 6 5 4 6 8 X 5 X 5 8 9 3 9 6 8 X 5 X 5 8 3 9 9 6 X X X 5 X S S S S S S S S S S 10 7 2 3 2 3 2 3 2 3 T T 1 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 4 3 2 3 2 3 2 3 2 3 5 3 2 3 1 3 2 3 2 3 5 2 2 3 2 4 2 3 2 3 5 S S 2 3 2 1 2 3 2 3 0 0 Sample Output 12 5 -1 22 12

R语言，在本地的Rstudio上，读入数据左上多了一个x?请教各位，谢谢！

Problem Description Zty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he has a habit that he does not like to solve a problem that is easy than problem he had solved. Now yifenfei give him n difficulty problems, and tell him their relative time to solve it after solving the other one. You should help zty to find a order of solving problems to solve more difficulty problem. You may sure zty first solve the problem 0 by costing 0 minute. Zty always choose cost more or equal time’s problem to solve. Input The input contains multiple test cases. Each test case include, first one integer n ( 2< n < 15).express the number of problem. Than n lines, each line include n integer Tij ( 0<=Tij<10), the i’s row and j’s col integer Tij express after solving the problem i, will cost Tij minute to solve the problem j. Output For each test case output the maximum number of problem zty can solved. Sample Input 3 0 0 0 1 0 1 1 0 0 3 0 2 2 1 0 1 1 1 0 5 0 1 2 3 1 0 0 2 3 1 0 0 0 3 1 0 0 0 0 2 0 0 0 0 0 Sample Output 3 2 4

Problem Description Give you a matrix(only contains 0 or 1),every time you can select a row or a column and delete all the '1' in this row or this column . Your task is to give out the minimum times of deleting all the '1' in the matrix. Input There are several test cases. The first line contains two integers n,m(1<=n,m<=100), n is the number of rows of the given matrix and m is the number of columns of the given matrix. The next n lines describe the matrix:each line contains m integer, which may be either ‘1’ or ‘0’. n=0 indicate the end of input. Output For each of the test cases, in the order given in the input, print one line containing the minimum times of deleting all the '1' in the matrix. Sample Input 3 3 0 0 0 1 0 1 0 1 0 0 Sample Output 2

R语言中我爬入了股票数据，为什么存进txt去以后行号就变成了数字 而不是月份了

Problem Description The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's call the missing tile 'x'; the object of the puzzle is to arrange the tiles so that they are ordered as: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x where the only legal operation is to exchange 'x' with one of the tiles with which it shares an edge. As an example, the following sequence of moves solves a slightly scrambled puzzle: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 5 6 7 8 5 6 7 8 5 6 7 8 5 6 7 8 9 x 10 12 9 10 x 12 9 10 11 12 9 10 11 12 13 14 11 15 13 14 11 15 13 14 x 15 13 14 15 x r-> d-> r-> The letters in the previous row indicate which neighbor of the 'x' tile is swapped with the 'x' tile at each step; legal values are 'r','l','u' and 'd', for right, left, up, and down, respectively. Not all puzzles can be solved; in 1870, a man named Sam Loyd was famous for distributing an unsolvable version of the puzzle, and frustrating many people. In fact, all you have to do to make a regular puzzle into an unsolvable one is to swap two tiles (not counting the missing 'x' tile, of course). In this problem, you will write a program for solving the less well-known 8-puzzle, composed of tiles on a three by three arrangement. Input You will receive, several descriptions of configuration of the 8 puzzle. One description is just a list of the tiles in their initial positions, with the rows listed from top to bottom, and the tiles listed from left to right within a row, where the tiles are represented by numbers 1 to 8, plus 'x'. For example, this puzzle 1 2 3 x 4 6 7 5 8 is described by this list: 1 2 3 x 4 6 7 5 8 Output You will print to standard output either the word ``unsolvable'', if the puzzle has no solution, or a string consisting entirely of the letters 'r', 'l', 'u' and 'd' that describes a series of moves that produce a solution. The string should include no spaces and start at the beginning of the line. Do not print a blank line between cases. Sample Input 2 3 4 1 5 x 7 6 8

<div class="post-text" itemprop="text"> <p>People go online and submit an article, with a title and description. And people often include links but they appear as basic text. I want a way in which when people include a url, it is recognized as a working link. I have written a code, but it only scans one row and doesn't seem to work in the actual table, as it is echoed outside of the table.</p> <p>Basically...i want a table where when a link is submitted, a hyperlink is made. Any ideas? This updated code below keeps the same thing going on.</p> <p>My code is below:</p> <pre><code> \$query = "SELECT * FROM rumours ORDER BY id DESC"; \$query = mysql_query(\$query) or die('MySQL Query Error: ' . mysql_error( \$connect )); while (\$row = mysql_fetch_assoc(\$query)) { \$id = \$row['id']; \$band = \$row['band']; \$title = \$row['Title']; \$description = \$row['description']; \$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; // The Text you want to filter for urls // Check if there is a url in the text if(preg_match(\$reg_exUrl, \$description, \$url)) { // make the urls hyper links preg_replace(\$reg_exUrl, '&lt;a href="'.\$url[0].'"&gt;'.\$url[0].'&lt;/a&gt;', \$description); } echo "&lt;table border='1'&gt;"; echo "&lt;tr&gt;"; echo "&lt;td&gt; \$title &lt;/td&gt;"; echo "&lt;/tr&gt;"; echo "&lt;tr&gt;"; echo "&lt;td class = 'td1'&gt; \$description &lt;/td&gt;"; echo "&lt;/tr&gt;"; echo "&lt;/table&gt;"; } </code></pre> </div>

Problem Description Give you a matrix(only contains 0 or 1),every time you can select a row or a column and delete all the '1' in this row or this column . Your task is to give out the minimum times of deleting all the '1' in the matrix. Input There are several test cases. The first line contains two integers n,m(1<=n,m<=100), n is the number of rows of the given matrix and m is the number of columns of the given matrix. The next n lines describe the matrix:each line contains m integer, which may be either ‘1’ or ‘0’. n=0 indicate the end of input. Output For each of the test cases, in the order given in the input, print one line containing the minimum times of deleting all the '1' in the matrix. Sample Input 3 3 0 0 0 1 0 1 0 1 0 0 Sample Output 2

（错误在哪里）R语言如何从文件中读取数据

> file.choose() [1] "C:\\Users\\HP\\Desktop\\新建文件夹\\data.txt" > data1<-read.table("data.txt",header=T) 错误于make.names(col.names, unique = TRUE) : '<ff><fe><77>'多字节字符串有错 data1<-read.table("data.txt",header=T,quote = FALSE, sep = " ", na = "NA", dec = ".", row.names = TRUE,col.names = TRUE) 错误于read.table("data.txt", header = T, quote = FALSE, sep = " ", : 引号符号集不对 > data1<-read.table("data.txt",header=T,sep = " ", na = "NA", dec = ".", row.names = FALSE,col.names = TRUE) 错误于read.table("data.txt", header = T, sep = " ", na = "NA", dec = ".", : 'row.names'设定得不对 >

String s = new String(" a ") 到底产生几个对象？

Linux面试题（2020最新版）

JVM内存结构和Java内存模型别再傻傻分不清了

loonggg读完需要3分钟速读仅需 1 分钟大家好，我是你们的校长。我之前讲过，这年头，只要肯动脑，肯行动，程序员凭借自己的技术，赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

85后蒋凡：28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门，他的人生底层逻辑是什么？...

MySQL数据库面试题（2020最新版）

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...