Try this:

Lines <- '1 2 0.1
2 3 0.2
3 1 0.3'

DF <- read.table(textConnection(Lines))
m <- matrix(0, ncol = nrow(DF), nrow = nrow(DF))
m[as.matrix(DF[1:2])] <- DF[[3]]

On Tue, Aug 10, 2010 at 3:03 PM, zhenjiang xu <zhenjiang.xu@gmail.com>wrote:

> Hi,
>
> I have a file like this:
> 1 2 0.1
> 2 3 0.2
> 3 1 0.3
>
> And I want to read it to create a matrix like this:
>     [,1]     [,2]    [,3]
> [1,]    0       0.1     0
> [2,]    0       0        0.2
> [3,]    0.3    0        0
>
> How can I do it efficiently? Thanks.
> --
> Best,
> Zhenjiang
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

