This is to continue on the topic of using the melt/cast functions in reshape to convert between long and wide format of data frame. Here is the example I found helpful in generating covariate table required for PEER (or Matrix_eQTL) analysis:

Here is my original covariate table:

 
Let's say we need to convert the categorical variables such as condition, cellType, batch, replicate, readLength, sex into indicators (Note: this is required by most regression programs like PEER or Matrix-eQTL, since for example the batch 5 does not match it's higher than batch 1, unlike the age or PMI). So, we need to convert this long format into wide format. Here is my R code for that:
 
library(reshape2)
categorical_varaibles = c("batch", "sex", "readsLength", "condition", "cellType", "replicate");
for(x in categorical_varaibles) {cvrt = cbind(cvrt, value=1); cvrt[,x]=paste0(x,cvrt[,x]); cvrt = dcast(cvrt, as.formula(paste0("... ~ ", x)), fill=0);}
 

Here is output:

 

reshape: from long to wide format(转)的更多相关文章

  1. MatterTrack Route Of Network Traffic :: Matter

    Python 1.1 基础 while语句 字符串边缘填充 列出文件夹中的指定文件类型 All Combinations For A List Of Objects Apply Operations ...

  2. R语言-推荐系统

    一.概述 目的:使用推荐系统可以给用户推荐更好的商品和服务,使得产品的利润更高 算法:协同过滤 协同过滤是推荐系统最常见的算法之一,算法适用用户过去的购买记录和偏好进行推荐 基于商品的协同过滤(IBC ...

  3. 机器学习之--kmeans聚类简单算法实例

    import numpy as np import sklearn.datasets #加载原数据 import matplotlib.pyplot as plt import random #点到各 ...

  4. python--numpy、pandas

    numpy 与 pandas 都是用来对数据进行处理的模块, 前者以array 为主体,后者以 DataFrame 为主体(让我想起了Spark的DataFrame 或RDD) 有说 pandas 是 ...

  5. [No0000D4]批处理全部代码详解Allbat

    COPY REM Copies one or more files from one location to another. REM [/d] - Allows the encrypted file ...

  6. pandas 数据结构基础与转换

    pandas 最常用的三种基本数据结构: 1.dataFrame: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Data ...

  7. Python Pandas -- Panel

    Pandas 中一维 series, 二维DataFrame, 三维Panel class pandas.Panel(data=None, items=None, major_axis=None, m ...

  8. Fisherfaces 算法的具体实现源码

    /* * Copyright (c) 2011. Philipp Wagner <bytefish[at]gmx[dot]de>. * Released to public domain ...

  9. 基础分类网络VGG

    vgg16是牛津大学视觉几何组(Oxford Visual Geometry Group)2014年提出的一个模型. vgg模型也得名于此. 2014年,vgg16拿了Imagenet Large S ...

随机推荐

  1. Unity3d中的PlayerPrefs游戏存档API的扩展

    功能 在游戏会话中储存和访问游戏存档.这个是持久化数据储存,比如保存游戏记录. 静态函数 DeleteAll Removes all keys and values from the preferen ...

  2. 回车键搜索 - Enter搜索

    今天写了个 搜索  想来发表发表 <!DOCTYPE html><html lang="en"><head> <meta charset= ...

  3. iOS UITableViewCell点击时子视图背景透明的解决方法

    在做iOS项目的开发中,UITableView控件的应用十分广泛.在进行自定义UITableViewCell时,经常遇到这样的问题:在UITableViewCell上面添加了一个有背景颜色的子视图,当 ...

  4. java Http消息传递之POST和GET两种方法--通过实用工具类来获取服务器资源

    实现该方法需要导入一些jar包 可以去一下地址下载: http://pan.baidu.com/s/1hqrJF7m /** * 实用工具类来获取服务器资源 * * get方法传送数据 * * 1.通 ...

  5. 少年,是时候换种更优雅的方式部署你的php代码了

    让我们来回忆下上次你是怎么发布你的代码的: 1. 先把线上的代码用ftp备份下来 2. 上传修改了的文件 3. 测试一下功能是否正常 4. 网站500了,赶紧用备份替换回去 5. 替换错了/替换漏了 ...

  6. jDialects:一个从Hibernate抽取的支持70多种数据库方言的原生SQL分页工具

    jDialects(https://git.oschina.net/drinkjava2/jdialects) 是一个收集了大多数已知数据库方言的Java小项目,通常可用来创建分页SQL和建表DDL语 ...

  7. Javascript中this关键字

    this 是谁调用的时候,指定的是谁,通俗一点讲就是,函数是谁执行是不是由其中一个对象点出来的那就是代表它, 比如执行对象a中b函数a.b();这个b函数中this代表a; 当换成var c=a.b; ...

  8. DirectFB 之 通过多Window实现多元素处理

    图像 设计 采用多window的方式实现显示,因为每个window可以独立的属性,比如刷新频率,也是我们最关注的 示例 /*************************************** ...

  9. PHP array_filter() 函数

    定义和用法 array_filter() 函数用回调函数过滤数组中的元素,如果自定义过滤函数返回 true,则被操作的数组的当前值就会被包含在返回的结果数组中, 并将结果组成一个新的数组.如果原数组是 ...

  10. 蓝桥杯-n级台阶-java

    /* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 * All rights reserved. * 文件名称: ...