I create data.table like this.
DT = data.table(A=c(1,2,3), B=c(1,2,3,4,5))
But I get this result.
A B
1: 1 1
2: 2 2
3: 3 3
4: 1 4
5: 2 5
but I'd like to get this.
A B
1: 1 1
2: 2 2
3: 3 3
4: NA 4
5: NA 5
How can I create data.table with different size?
Change column and row widthSelect the rows or columns and then select Layout and choose your height and width. Select View > Ruler checkbox, select the cell you want, and then drag the markers on the ruler. Note: In Excel, select Home > Format, and then select Column Width.
Resize rows, columns, or cells On the Layout tab, you can specify the custom height and width. To resize specific rows or column, click on a cell and then adjust the row/column. To make multiple rows or columns the same size, select the columns or rows and click Distribute Rows or Distribute Columns.
We keep the vector
of unequal length in a list
('lst'), then loop through the list
elements, append NA at the end and convert to data.table
.
lst <- list(A=c(1,2,3), B=c(1,2,3,4,5))
DT <- setDT(lapply(lst, `length<-`, max(lengths(lst))))[]
DT
# A B
#1: 1 1
#2: 2 2
#3: 3 3
#4: NA 4
#5: NA 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With