# まずは、見つけたら印字 setwd("D:/R/Sample") x <- read.table("cwlist.txt", as.is=1) y <- "縦横無○" for ( i in 1:length(x[,1]) ) { score <- 0 for ( j in 1:4 ) { if ( substr(x[i,],j,j) == substr(y,j,j) ) score <- score +1 } if ( score >= 3 ) { print( i ); print( x[i,] ) } } # 例1 setwd("D:/R/Sample") x <- read.table("cwlist.txt", as.is=1) y <- "縦横無○" s <- c( ) for ( i in 1:length(x[,1]) ) { score <- 0 for ( j in 1:4 ) { if ( substr(x[i,],j,j) == substr(y,j,j) ) score <- score +1 } if ( score >= 3 ) s <- c(s,i) } print( s ); print( x[s,] ) # 例2 setwd("D:/R/Sample") x <- read.table("cwlist.txt", as.is=1) y <- "縦横無○" s <- c( ) for ( i in 1:length(x[,1]) ) { if ( length(agrep( y, x[i,] )) != 0 ) s <- c(s,i) } print( s ); print( x[s,] )