[R] Two problems

David A Richmond richmond at saintmarys.edu
Thu Apr 18 22:49:45 CEST 2002


On Thu, 18 Apr 2002, Ambrosini Alessandro wrote:

> Hello! Two questions:
>
> 1: I have to import a matrix of adjacency from a file of a software that is
> not R (for example "bloc notes" of Windows). The problem is that the matrix
> is not in the explicit form as
>  0 1 1
>  1 0 0
>  1 0 0
> but it is a scattered matrix where in each row there are two nodes that have
> a direct path.
> The matrix is
>
>  a   b
>  a   c
>  b   a
>  c   a

one more thing: here's how to read from a text file into a matrix of
strings so that you can use my charmatching solution:

> lines <- readLines("textfile.txt")
> lines
[1] "a b" "a c" "b a" "c a"
> chars <- c(strsplit(lines," "),recursive=TRUE)
> chars
[1] "a" "b" "a" "c" "b" "a" "c" "a"
> chars <- t(matrix(chars,2,length(chars)/2))
> chars
     [,1] [,2]
[1,] "a"  "b"
[2,] "a"  "c"
[3,] "b"  "a"
[4,] "c"  "a"
>

dave r.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list