0

I would like to create a squared matrix with 3003 rows an 3003 columns (number of rows in MyData) It worked that the matrix is created and filled with 3003 rows but only 100 columns and I do not get why.

 library(sp)  
 Dists <- matrix(0, nrow=nrow(MyData), ncol = nrow(MyData))

    for(n in 1:nrow(MyData)){
      Dists[n,] <- spDistsN1(pt = c(MyData$lng[n], MyData$lat[n]), 
                             pts =  as.matrix(MyData[,c("lng","lat")]))

Thanks for your help.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
Laura94
  • 1
  • 1
  • 1
    Welcome to SO ! Please read [How to make a great R reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and edit your question accordingly. – etienne Nov 25 '16 at 08:56
  • What is the value of `nrow(MyData)`? – Roman Luštrik Nov 25 '16 at 09:03
  • Sometimes they're there, but you just can't see them. Have you checked nrow(Dists)? – rosscova Nov 25 '16 at 09:03
  • 2
    `MyData <- data.frame(x=runif(3003),y=runif(3003))` then your code, then `str(Dists)` shows that Dists is 3003x3003 as expected. If you're getting a different answer, you'll need to give some data that generates the problem – Miff Nov 25 '16 at 09:03
  • Thanks for help, it worked ... I just started working with R – Laura94 Nov 25 '16 at 09:08

1 Answers1

3

Since you tagged RStudio I assume that you view your data in RStudio using View() (e.g. by clicking on the data object in the right panel of RStudio).

Have a look at this document: Using the Data Viewer

It tells us:

While rows are unbounded, columns are capped at 100. It’s not currently possible to virtualize columns in the same way as rows, and large numbers of columns cause the interface to slow significantly.

However, your matrix will still contain all columns, you can check this with dim(myMatrix)

PhillipD
  • 1,797
  • 1
  • 13
  • 23