0

I want to create a matrix from character vector similar to:

comments <- c("abc", "lol")
comm_matrix <- matrix(data=comments, ncol=3, nrow=1)

I want to get matrix, but with NA if ncol > nchar in vector:

[,1] [,2] [,3]
abc  lol  NA 

Instead of default:

[,1] [,2] [,3]
abc  lol  abc
Mikołaj
  • 385
  • 4
  • 17
  • 2
    If you follow [Rich Scriven's answer](https://stackoverflow.com/a/29957940/8583393) in the linked post it will give you what you're looking for. – markus Aug 04 '18 at 09:53

1 Answers1

1

Thank's mates, the solution is:

comments <- c("abc", "lol")
length(comments) <-prod(dim(matrix(comments, ncol=3)))
comm_matrix <- matrix(data=comments, ncol=3, nrow=1, byrow=TRUE)
comm_matrix

#    [,1]  [,2]  [,3]
#[1,] "abc" "lol" NA  
Mikołaj
  • 385
  • 4
  • 17