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. Jackson序列化实例

    参考文章 Jackson使用ContextualSerializer在序列化时获取字段注解的属性 使用BeanSerializerModifier定制jackson的自定义序列化(null值的处理) ...

  2. 对比字节流和字符流,回答为什么FileReader不能用来拷贝图片

    FileReader是输入字符流,拷贝文件没问题,但拷贝图片就有问题了. 假设是在windows下,FileReader用的是GBK码表,一个字符最多用2个字节代表.2个字节就是2的16次方,即有65 ...

  3. css常用技巧集合

    1 不想让按钮touch时有蓝色的边框或半透明灰色遮罩(根据系统而定) /*解决方式一*/ -webkit-tap-highlight-color:rgba(0,0,0,0); -webkit-use ...

  4. mysql数据库实操笔记20170418

    一.建立商品分类表和价格表: 1.分类表`sankeq``sankeq`CREATE TABLE cs_mysql11(id INT(11) NOT NULL AUTO_INCREMENT,categ ...

  5. AFNetworking 内部详解

    AFNetworking 是一个适用于IOS 和 Mac OSX 两个平台的网络库,他是在Foundation URL Loading System  基础上进行的一套封装 ,并提供了丰富的API接口 ...

  6. Mac 下载安装MySQL

    step 1. 从官网上下载MySQL Community Server step 2. 安装MySQL step 3. 配置mysql和mysqladmin的alias $ vim ~/.bashr ...

  7. JSON 解析工具的封装(Java)

    JSON 解析工具的封装(Java) 一直想有一个属于自己的JSON工具,今天终于弄好了..... 1.添加pom依赖包 <!--json解析--> <dependency> ...

  8. 二、AspNet Core添加EF的基本方法(简略版):

    _/\__ ---==/ \\ |. \|\ | ) \\\ \_/ | //|\\ / \\\/\\ 1.在Project.json的dependencies选项中添加以下引用: "Mic ...

  9. C语言的一些基础

    一.C语言基础: 1.1.main函数是入口函数,用于进行link. 1.2..sln是解决方案的管理文件. 1.3.int:32位.short:16位.long:32位.long long:64位. ...

  10. Linux基础(4)

    Linux基础(四) 通过前面的知识的学习,来现学现卖咯! 1.题目:集群搭建 1.1.部署nginx反向代理三个web服务,调度算法使用加权轮询: 1.2.所有web服务使用共享存储nfs,保证所有 ...