首页 > 解决方案 > Create single objects form a table containing them

问题描述

Here is my problem with R:

I have a table similar to this:

TABLE_NAME          COLUM_NAME          DATA_TYPE 
table_1               DATA              DATE
table_1               NAME              VARCHAR2
table_1               SURNAME           VARCHAR2
table_2               DATA              DATE
table_2               PACK              NUMBER

what i want to do is to create 2 different table from this based on the TABLE_NAME value that will have TABLE_NAME as name. Like this

table_1

COLUM_NAME          DATA_TYPE 
   DATA              DATE
   NAME              VARCHAR2
   SURNAME           VARCHAR2

table_2

COLUM_NAME          DATA_TYPE
DATA              DATE
PACK              NUMBER

This way i can create a catalog of my tables, synonym and view of my db (with ROracle is not possible to fetch such metadata from the connection).

How can i Achieve this?

标签: rroracle

解决方案


We can use split to create a list of data.frames

lst1 <- split(df1[-1], df1[[1]])
lst1
#$table_1
#  COLUM_NAME DATA_TYPE
#1       DATA      DATE
#2       NAME  VARCHAR2
#3    SURNAME  VARCHAR2

#$table_2
#  COLUM_NAME DATA_TYPE
#4       DATA      DATE
#5       PACK    NUMBER

Here, split is splitting the data.frame based on the factor provided (f in split). It looks for rows that have the same elements in 'TABLE_NAME' and group them together and return a list of those similar rows


推荐阅读