half_matrix
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| half_matrix [2008/01/29 10:28] – created heidi | half_matrix [2008/09/23 09:44] (current) – heidi | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== read data between XML tags ====== | + | ====== read half matrix |
| - | * file: Node auslesen_BspTabelle.r | + | * file: read_tag-halfMatrix.r |
| - | * document page: 19 | + | * document page: 37 |
| \\ | \\ | ||
| **code:** | **code:** | ||
| < | < | ||
| + | #----open XML package------------------------------------------------- | ||
| + | library(XML) | ||
| + | |||
| + | #----read data between an XML tag------------------------------------- | ||
| + | filename = " | ||
| + | tag = "// | ||
| + | doc = xmlTreeParse(filename, | ||
| + | ch = getNodeSet(doc, | ||
| + | |||
| + | subDoc = xmlDoc(ch[[1]]) | ||
| + | tagData <- xpathApply(subDoc, | ||
| + | free(subDoc) | ||
| + | |||
| + | |||
| + | # | ||
| + | #----split string---- | ||
| + | tagData2 <- as.character(tagData) | ||
| + | |||
| + | tagData3 <- strsplit(tagData2, | ||
| + | tagMatrix <- as.matrix(as.data.frame(tagData3)) | ||
| + | tagMatrix <- tagMatrix[4: | ||
| + | tagMatrix | ||
| + | Data <- strsplit(tagMatrix, | ||
| + | |||
| + | #----to numeric matrix---- | ||
| + | Row <- length(Data) | ||
| + | |||
| + | Matrix <- as.matrix(as.data.frame(Data[1])) | ||
| + | Matrix <- rbind(Matrix, | ||
| + | Matrix <- Matrix[3: | ||
| + | numericList <- as.numeric(Matrix) | ||
| + | numericMatrix <- t(as.matrix(numericList)) | ||
| + | |||
| + | for(n in 2:(Row)){ | ||
| + | nextrow <- as.matrix(as.data.frame(Data[n])) | ||
| + | nextrow <- rbind(nextrow, | ||
| + | nextrow <- nextrow[3: | ||
| + | numericList <- as.numeric(nextrow) | ||
| + | numericMatrix <- rbind(numericMatrix, | ||
| + | } | ||
| + | numericMatrix | ||
| + | </ | ||
| + | |||
| + | ===== read half matrix out of full matrix ===== | ||
| + | * file: read_tag-halfOutOfFullMatrix.r | ||
| + | |||
| + | \\ | ||
| + | **code:** | ||
| + | < | ||
| + | #----open XML package----------------------------------------------------------- | ||
| + | library(XML) | ||
| + | |||
| + | #----read data between an XML tag----------------------------------------------- | ||
| + | filename = " | ||
| + | tag = "// | ||
| + | doc = xmlTreeParse(filename, | ||
| + | ch = getNodeSet(doc, | ||
| + | |||
| + | subDoc = xmlDoc(ch[[1]]) | ||
| + | tagData <- xpathApply(subDoc, | ||
| + | free(subDoc) | ||
| + | |||
| + | |||
| + | # | ||
| + | #----split string---- | ||
| + | tagData2 <- as.character(xmlText) | ||
| + | |||
| + | tagData3 <- strsplit(tagData2, | ||
| + | tagMatrix <- as.matrix(as.data.frame(tagData3)) | ||
| + | tagMatrix <- gsub(" + ", " ", tagMatrix) | ||
| + | |||
| + | tagMatrix <- tagMatrix[4: | ||
| + | Data <- strsplit(tagMatrix, | ||
| + | |||
| + | #----to numeric matrix---- | ||
| + | Row <- length(Data) | ||
| + | |||
| + | Matrix <- matrix(NA, ncol=1, nrow=Row) | ||
| + | numericList <- as.numeric(Matrix) | ||
| + | numericMatrix <- t(as.matrix(numericList)) | ||
| + | |||
| + | for(n in 2:(Row)){ | ||
| + | nextrow <- as.matrix(as.data.frame(Data[[n]][3: | ||
| + | nextrow <- rbind(nextrow, | ||
| + | #nextrow <- nextrow[3: | ||
| + | numericList <- as.numeric(nextrow) | ||
| + | numericMatrix <- rbind(numericMatrix, | ||
| + | } | ||
| + | numericMatrix | ||
| + | </ | ||
| + | |||
half_matrix.1201598889.txt.gz · Last modified: 2008/07/22 13:30 (external edit)