r - 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?
解决方案
We can use split
to create a list
of data.frame
s
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
推荐阅读
- java - 在枚举中使用最终常量
- r - 在另一个变量中设置函数变量
- java - 如何更好地匹配引号之间的字符串
- javascript - 谷歌洛夫菲尔德的状态
- laravel - 尝试在不同文件夹中运行两个具有相同名称的迁移时出现问题 Laravel
- javascript - 我有两个包含对象的数组,我想比较值并返回更改键值 pait 和数组位置
- javascript - 如何在 Heroku 上发现我的内部和外部 IP 地址?
- android - React Native ./gradlew bundleRelease 或 assembleRelease 命令无限加载
- python - 如何为python 2.7创建虚拟环境
- rust - 如何验证结构中的选项参数值