의 패키지 인 RQDA를 사용하여 텍스트를 수동으로 코딩합니다. 최종 rqda 파일은 sql 데이터베이스입니다. 저는 텍스트로 문장을 코딩하고 다른 코드를 사용했으며 코드 카테고리 (예 : 코드 카테고리 "actor_party"및 관련 코드 "사회 주의적", "자유주의", "보수적"등)에서 을 코드 범주에 포함 시켰습니다. 나는 코딩을 마친 후 으로 소셜 네트워크 분석을 수행하려고합니다. 이를 위해 SQL 데이터베이스를 작성하여 각 코드 카테고리가 각 행의 특정 코드로 고유 한 컬럼을 갖도록합니다. 모든 코드는 catid (= 코드 범주 번호), fid (파일 식별 번호) & selfirst (각 코드의 시작) 속성으로 식별 할 수 있습니다. 이렇게함으로써 특정 catid 인 fyd & selfirst가 각 coded 문에 대해 선택되어 sqlite가 각 코딩을 고유 한 것으로 식별 할 수 있습니다 (추가적으로 R 스크립트에서 아래에서 볼 수 있듯이 각 유효한 코딩에 대해 status = 1이 있어야 함). 선출되기도 함).
버전 0.99-779, rqda, 버전 0.2-7 및 rsqlite 1.0.0에서 rstudio을 사용합니다.rqda 파일을 sql 파일로 변환
그래서, 다음 R 코드가 사용됩니다 :
library(RSQLite) # load Package RSQLite
setwd("C:/...")
system("ls *.rqda", show=TRUE)
sqlite <- dbDriver("SQLite")
#specifing the file
qdadb <- dbConnect(sqlite,"My_data.rqda")
dbListTables(qdadb)
dbListFields(qdadb, "coding") # that's where the codings are stored
catid <- dbGetQuery(qdadb, "select distinct(catid) from treecode where status = 1 ORDER BY catid")
i <- 1
table <- dbGetQuery(qdadb, "select fid, selfirst from coding where status = 1 GROUP BY fid, selfirst")
while(i <= max(catid)) {
ids <- dbGetQuery(qdadb, paste("select cid from treecode where (catid = ",i," and status = 1)", sep=""));
t <- dbGetQuery(qdadb, paste("select cid, fid, selfirst from coding where (cid in (", paste(as.character(ids$cid), sep="' '", collapse=","), ") and status = 1)", sep=""));
table <- merge(table, t, by = c("fid","selfirst"), all.x = T);
i <- i + 1;
}
# warnings are created because of the same columns which are duplicated by the merging
colnames(table) <- c("fid", "selfirst", dbGetQuery(qdadb, "select name from codecat where status = 1")[,1]) #each code has attributed a unique f(ile)id and selfirst (it's the unique starting point of each coding)
# see below for an example of such a created table
library(car) # Companion to Applied Regression package
# years - catid = 1
table$A00_time_frame <- recode(table$A00_time_frame, '1 = 2010; 2 = 2011; 3 = 2012; 4 = 2013; 5 = 2014; 6 = 2015')
# Sources - catid = 2
ids <- dbGetQuery(qdadb, "select cid from treecode where (catid = 2 and status = 1)")[,1]
values <- dbGetQuery(qdadb, paste("select name from freecode where (id in(", paste(ids, collapse = ","), ") and status = 1)"))[,1]
table$B00_source <- recode(table$B00_source, paste0("'", paste(ids,"'='", values, collapse = "';'", sep=""),"'", sep=""))
# Claimant type - catid = 3
ids <- dbGetQuery(qdadb, "select cid from treecode where (catid = 3 and status = 1)")[,1]
values <- dbGetQuery(qdadb, paste("select name from freecode where (id in(", paste(ids, collapse = ","), ") and status = 1)"))[,1]
table$C00_claimant_type <- recode(table$C00_claimant_type, paste0("'",
paste(ids,"'='", values, collapse = "';'", sep=""),"'", sep=""))
and so until "catid = 20"
이 밖으로 작동하고 다음과 같습니다 이 example_table [이 테이블 행 844까지 계속된다 - 단지 FID가 상승입니다]
비록 이것이 작동하고 생성 된 테이블이 전체 코드 수와 일치하더라도 몇 가지 실수가 일어나고 있습니다. 일부 코드는 올바른 문장 카테고리에 연결되어 있지만 올바른 코드 카테고리에는 연결되어 있지 않지만 올바른 코드 카테고리에는 연결되어 있지 않습니다.
아직 R (스튜디오)의 초보자이며 설명 할 수 없습니다. 뭐가 잘못 됐어.
여기에 문제가 있거나 실수가 될 수있는 아이디어가 있고 어떻게 고칠 수 있습니까? 요청에 따라
, 내 파일 :
어떤 조언이나 도움을 매우 환영을 공유 할 기쁘게 생각합니다!
편집 : 여기 당신이 그것을 (나는 생각하기 때문에 파일이 변환 문제 자체가 될 수도는 rqda-형식으로되어 있습니다) 재현 할 수있는 내 데이터의 하위 집합에 a link입니다 .
그리고 두 가지 예를 들어 보겠습니다. 4553 selfirst, FID 95 다음 코딩 '디 벨트'와 단 이후 다음 'E02_European_Commission'+ 'G10_Cameroon'
- R에 "테이블"작성함으로써
는, 다음 행이
1
를 식별 할 수있다 , 원래 rqda 파일의 코딩을 확인하면 'Cameroon'코드는 fid 70, selfirst 5082 및 2010 년 'Welt'에서이 파일에 없습니다.
-
- fid 90, selfirst 959 및 year '2011'은 코드 'CDU'를 표시하고 마지막 행 'special claimant'는 'Martin Schulz'라는 이름을 표시합니다.
그러나 원본 rqda 파일에서 코딩을 확인하면 해당 하위 세트의 'Martin Schulz'코드에 코딩이 추가되지 않습니다. 나는 희망
- fid 90, selfirst 959 및 year '2011'은 코드 'CDU'를 표시하고 마지막 행 'special claimant'는 'Martin Schulz'라는 이름을 표시합니다.
,이 두 가지 예는 문제를 설명하고 당신에게에서 각각 문제가 무엇인지 볼 수있는 아이디어를 제공합니다.
미안하지만 처음에는 제공하지 않았습니다!
질문이 너무 깁니다. 재생산 가능한 예제를 게시 할 수 있습니까? http://stackoverflow.com/q/5963269/946850 – krlmlr