[datatable-help] Construct a new data table from another
Chris Neff
caneff at gmail.com
Mon Jul 21 13:10:16 CEST 2014
DT = data.table(A=letters[1:5],B=rnorm(5),C=rexp(5),D=runif(5))
DT2=DT[,c(1,4,2),with=FALSE]
# If you really want the name changes
setnames(DT2, c('a','d','B'))
On Mon Jul 21 2014 at 7:01:26 AM, Frank S. <f_j_rod at hotmail.com> wrote:
> Hi everyone,
>
> For instance, let's suppose I have the an initial data frame DF, and I
> want to
> rename and reorder some of its columns, so that the desired result is
> expressed by DF2:
>
>
> set.seed(100)
> DF = data.frame(A=letters[1:5],B=rnorm(5),C=rexp(5),D=runif(5))
> DF2 <- data.frame(a=DF[,1],d=DF[,4],B=DF[,2])
>
> If I do the equivalent operations under data table format, I'm onñy able
> to obtain
> the same result with the following code:
>
>
> set.seed(100)
> DT = data.table(A=letters[1:5],B=rnorm(5),C=rexp(5),D=runif(5))
> DT2 <-
> data.table(a=DT[,1,with=FALSE],d=DT[,4,with=FALSE],B=DT[,2,with=FALSE])
>
>
> Please, is it possible to get the same result with a more simply code?
> Thanks!
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/
> listinfo/datatable-help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20140721/a7630454/attachment.html>
More information about the datatable-help
mailing list