Home > other >  (turn) R language, how to realize the found in the matrix with a string contains a word line, and de
(turn) R language, how to realize the found in the matrix with a string contains a word line, and de

Time:11-27

# R statement below is found with a string of matrix contains "American" 2 words, and to bring the line to delete #
Setwd (" C:/Users/wang/Documents/R ")
A<- read. CSV (' ceshi20200318. CSV)
As the matrix (A)
The library (stringr)
For (I in 1:6)
{
If
(str_detect (A (I, 1), "us")==TRUE)
{A<-a [-i,]}
The else A<-a
I=I + 1
}


# # below is the content with the string matrix

A1, a2, a3, a4 a5
3, 4, 3 y
China1 2 north Korea 6 5
X Japan 2 0 1
The United States 3 5 z 2
The June 5 July 2
Japan 2 4 1 9


Now perform delete line 4 R command can only be "the United States 3 5 z 2" stop, no longer continue to execute, cannot be deleted line 5 "U.S. June 5 July 2," don't know what the reason is,

CodePudding user response:

Because delete the fourth row, fifth line becomes the fourth row
  • Related