rm(list=ls())
library(stringr)
library(dplyr)
input <- read.csv("C:\\Users\\이해리\\Desktop\\multi\\TH_facial_cleanser.csv")
1step 대문자를 소문자로 치환
input$aa<- tolower(input$top_title)
2step 문자열에서 문자 분리
input$bb <- strsplit(input$aa, split="")
3step dataframe 생성
rows <- input
cols <- input
mat <- matrix(nrow=235, ncol=235)
rownames(mat) <- input$top_title
colnames(mat) <- input$top_title
mat <- as.data.frame(mat)
mat_70 <- mat
class(mat)
4step 값 삽입
for (n in 1:235){
a <- input$bb[[n]]
for (m in 1:235){
b <- input$bb[[m]]
x <- a %in% b
x1 <- (length(which(x=="TRUE"))/length(a))
mat[n,m] <- x1
}
}
70% 이상 값 추출
for (n in 1:235){
a <- input$bb[[n]]
for (m in 1:235){
b <- input$bb[[m]]
x <- a %in% b
x1 <- (length(which(x=="TRUE"))/length(a))
if (x1 >= 0.7){
mat_70[n,m] <- x1
}else {
mat_70[n,m] <- 0
}
}
}
write.csv(mat_70,"C:\\Users\\이해리\\Desktop\\multi\\TH_facial_cleanser_check.csv", row.names=TRUE )