Re: [R] R dataframe question

2014-01-25 Thread arun
Hi, dat1 <- read.table(text="X1 1,1 1,2 1,3 2,1 2,2 2,3 3,1 3,2 3,3",sep="",header=TRUE)  dat2 <- setNames(as.data.frame(matrix(dat1[,1],3,3)),paste0("X",1:3)) str(dat2) #'data.frame':    3 obs. of  3 variables: # $ X1: Factor w/ 3 levels "1,1","1,2","1,3": 1 2 3 # $ X2: Factor w/ 3 levels "2,1",

Re: [R] R dataframe question

2014-01-25 Thread arun
Hi, The question is not clear. set.seed(45)  spe <- data.frame(Col1=sample(c(1:10,letters[1:2]),400,replace=TRUE))  mat1 <- matrix(spe[,1],nrow=20,ncol=20) #If you want to replace the non-numeric values with NAs,  mat2 <- matrix(as.numeric(as.character(spe[,1])),nrow=20,ncol=20) A.K. Hell