User Tools

Site Tools


full_matrix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
full_matrix [2008/01/29 10:28] – created heidifull_matrix [2008/07/22 13:31] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== read data between XML tags ====== +====== read full matrix data ====== 
-  * file: Node auslesen_BspTabelle.r +  * file: read_tag-fullMatrix.r 
-  * document page: 19+  * document page: 38
  
 \\ \\
 **code:** **code:**
 <code> <code>
 +#----open XML package-----------------------------------------------------------
 +library(XML)
 +
 +#----read data between an XML tag-----------------------------------------------
 +filename = "D:/Heidi/Master/R_Daten/XML/XML_with_inserted_data.xml"
 +tag = "//pairwise_differences"
 +doc = xmlTreeParse(filename, useInternal = TRUE)
 +ch = getNodeSet(doc, tag)
 +
 +subDoc = xmlDoc(ch[[1]])
 +tagData <- xpathApply(subDoc, tag, xmlValue)
 +free(subDoc)
 +#print(tagData, indent=FALSE)
 +
 +
 +#----convert string data (full matrix) to a numeric matrix----------------------
 +#----split string----
 +tagData2 <- as.character(tagData)
 +
 +tagData3 <- strsplit(tagData2, "\n")
 +tagMatrix <- as.matrix(as.data.frame(tagData3))
 +tagMatrix <- gsub(" + ", " ", tagMatrix)   # trim white space
 +
 +tagMatrix <- tagMatrix[12:nrow(tagMatrix)]
 +Data <- strsplit(tagMatrix, " ")
 +
 +#----to numeric matrix----
 +Row <- length(Data)
 +
 +Matrix <- as.matrix(as.data.frame(Data[1]))
 +Matrix <- Matrix[3:(nrow(Matrix))]
 +Matrix <- as.numeric(Matrix)
 +numericMatrix <- t(as.matrix(Matrix))
 +
 +for(n in 2:(Row)){
 +  nextrow <- as.matrix(as.data.frame(Data[n]))
 +  nextrow <- nextrow[3:(nrow(nextrow))]
 +  nextrow <- as.numeric(nextrow)
 +  numericMatrix <- rbind(numericMatrix, t(as.matrix(nextrow)))
 +}
 +
 +numericMatrix
 +</code>
full_matrix.1201598900.txt.gz · Last modified: 2008/07/22 13:30 (external edit)