[R] Print specific matrix value???

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Jan 10 19:53:32 CET 2009



Nidhi Kohli wrote:
> Hello All,
> 
> I'm trying to print specific row and column for Observed_Scores matrix, however, when I execute the command "Observed_Scores[1,1]", I get the message "Error in Observed_Scores[1, 1] : incorrect number of dimensions". Could you please help and let me know where is the mistake? Here is my program:
> 
> 
> library(ltm)
> library(psych)
> 
> # Settting the working directory path to C:/NCME
> 
> path="C:/NCME"
> setwd(path)
> 
> #IRT Data Simulation Routine#
> 
> n.exams = 500   #Sets number of examinees to be generated#
> n.items = 20     #Sets number of items to be generated#
> 
> #The following intialize empty (NA) vectors or matrices#
> beta.values = rep(NA,n.items)
> resp.prob = matrix(rep(NA,n.exams*n.items),nrow=n.exams,ncol=n.items)
> Observed_Scores = matrix(rep(NA,n.exams*n.items),nrow=n.exams,ncol=n.items)
> 
> 
> #filling item parameters into beta.values
> beta.values = runif(n.items,-2,2)
> 
> #Calculating Threshold
> thresh.values = .5 * beta.values
> 
> 
> #for (i in 1:10)
> #{
> 
> #Using the function to generate the data
> GenData <- congeneric.sim(N=500, loads = rep(.5,20), err=NULL, short = FALSE)
> Observed_Scores = GenData[1]




Say

   str(Observed_Scores)

and find that Observed_Scores is not a matrix but a list!
If you want to extract the matrix (first element of GenData), then use
   Observed_Scores = GenData[[1]]

Uwe Ligges



> Regards
> Nidhi Kohli
> 
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list