?set?
> d=data.table(x=1:5,y=11:15,z=letters[1:5])
> set(d, 3L, 1:3, NA_character_)
> d
x y z
1: 1 11 a
2: 2 12 b
3: NA NA NA
4: 4 14 d
5: 5 15 e
> str(d)
Classes ‘data.table’ and 'data.frame': 5 obs. of 3 variables:
$ x: int 1 2 NA 4 5
$ y: int 11 12 NA 14 15
$ z: chr "a" "b" NA "d" ...
- attr(*, ".internal.selfref")=<externalptr>
:
> d=data.table(x=1:5,y=11:15,z=letters[1:5])
> d[3] <- NA_character_
> str(d)
Classes ‘data.table’ and 'data.frame': 5 obs. of 3 variables:
$ x: int 1 2 NA 4 5
$ y: int 11 12 NA 14 15
$ z: chr "a" "b" NA "d" ...
- attr(*, ".internal.selfref")=<externalptr>
[ ] set() - , @mnel :
DT[rownum, names(DT) := .SD[NA]]
set ( , ). , ( double integer), , RHS.
if( (isReal(RHS) && (TYPEOF(targetcol)==INTSXP || isLogical(targetcol))) ||
(TYPEOF(RHS)==INTSXP && isLogical(targetcol)) ||
(isString(targetcol))) {
if (isReal(RHS)) s3="; may have truncated precision"; else s3="";
warning("Coerced '%s' RHS to '%s' to match the column type%s. ... <s3> ...
}
assign.c :
https://r-forge.r-project.org/scm/viewvc.php/pkg/src/assign.c?view=markup&root=datatable
, :
FR # 2551 Singleton: = RHS ,
.
In general, where it data.tablecautiously warns you of potential problems or inefficiencies, in this case, when you want to install a set of columns of different types, wrap with suppressWarnings()- this is another way.
source
share