[R] help for matrix formation.

Mulholland, Tom Tom.Mulholland at dpi.wa.gov.au
Thu Mar 17 07:12:54 CET 2005


I'm not sure I am answereing your question, but here goes

# Create a vector with 2400 items
x <- runif(2400)

# Create a 600 by 4 matrix
y <- matrix(x,ncol = 4)

#If you needed the matrix to be done row by row
#y <- matrix(x,ncol = 4,byrow = T)

# Extract values from a particular part of the matrix
z <- y[500,3]  #row 500 column 3
z

# Extract values that meet certain criterion
z <- y[y < 0.01]
z

# Find postion of those that are extracted
which(y < 0.01)

HTH, Tom


> -----Original Message-----
> From: Lakshmi Dhevi Baskar [mailto:lavanya_ldb2000 at yahoo.co.in]
> Sent: Thursday, 17 March 2005 1:16 PM
> To: r-help-request at stat.math.ethz.ch
> Cc: r-help at stat.math.ethz.ch
> Subject: [R] help for matrix formation.
> 
> 
> Dear people, 
> 
>  I've been  trying to find a  way to do the following. 
> 
> I have a data set in text file with 3 columns and 2400 rows. 
> i tried to read the table as
> fisrt<-("ex.txt",header=FALSE)
>  
> I would like to read the third column values (which has 2400 
> value) and split them into matrix of size (600,4):
>  
> as 
> first 600 column values in first column in matrix and next 
> 600 next values(600 to 1200) as values in second column in 
> matrix and so on.
>  
> and could you also suggest me how to retrieve those items in 
> matrix like matrix(520,3) =0 ...
>  
> thanks in advance for the help.
>  
> 
> 		
> ---------------------------------
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list