[R] (no subject)
Allan Engelhardt
allane at cybaea.com
Fri Jun 25 16:33:18 CEST 2010
Maybe something like:
y <- readLines("foo")
z <- strsplit(y, ",")
cols <- sort(unique(unlist(z))) # Assuming this is what you want for
column names....
m <- matrix(0, nrow=length(z), ncol=length(cols),
dimnames=list(as.character(1:length(z)), cols))
for (i in 1:length(z)) {
m[i, z[[i]]] <- 1
}
print(m)
# A B C D E F G O
# 1 1 1 1 1 0 0 1 0
# 2 1 0 1 0 1 0 0 1
# 3 0 0 0 0 0 1 1 0
Hope this helps you a little.
Allan
On 25/06/10 13:00, ricardo.sousa2001 at portugalmail.pt wrote:
> Hello,
> I'm new in using the R, but from what I read is an excellent tool.
> Would you like if I could help, I am trying create an array from
> reading a text file.
>
> The idea is to read the file, and transform the data in binary
> format, for example. The calves of this file format.
>
>
> A,B,C,D,G
> A,C,E,O
> F,G
>
>
> Put this away
>
> a b c d e f g o
> 1 1 1 1 1 0 0 1 0
> 2 1 0 1 0 1 0 0 1
> 3 0 0 0 0 0 1 0 0
>
> and display in monitor.
>
> Thanks for the help
>
More information about the R-help
mailing list