R matrix 转换为 dataframe
2024-09-01 07:34:18
When I try converting a matrix to a data frame, it works for me: > x <- matrix(1:6,ncol=2,dimnames=list(LETTERS[1:3],letters[24:25]))
> data.frame(x)
x y
A 1 4
B 2 5
C 3 6
> str(data.frame(x))
`data.frame': 3 obs. of 2 variables:
$ x: int 1 2 3
$ y: int 4 5 6
> You can also use as.data.frame() to convert a matrix to a data.frame
(but note that if colnames are missing form the matrix, as.data.frame()
constructs different colnames than does data.frame(). =========================================
> data <- c(0.1, 0.2, 0.3, 0.3, 0.4, 0.5)
> dimnames <- list(time=c(0, 0.5, 1), name=c("C_0", "C_1"))
> mat <- matrix(data, ncol=2, nrow=3, dimnames=dimnames)
> as.data.frame(as.table(mat))
time name Freq
1 0 C_0 0.1
2 0.5 C_0 0.2
3 1 C_0 0.3
4 0 C_1 0.3
5 0.5 C_1 0.4
6 1 C_1 0.5
=========================================
REF:
https://stackoverflow.com/questions/15885111/create-data-frame-from-a-matrix-in-r
https://stat.ethz.ch/pipermail/r-help/2006-January/085978.html
最新文章
- 普通硬件就能破解GSM A5加密算法
- 如何用SQL语句实现Mysql数据库的备份与还原
- [2016.01.18]文本替换专家 v5.3
- Eclipse+Tomcat+MAVEN+SVN项目完整环境搭建
- Codeforces Round #222 (Div. 1) C. Captains Mode 对弈+dp
- JRE下的rt.jar、tools.jar
- 自制单片机之十一……模数转换IC ADC0809
- java decompiler如何去掉行号
- flask-session组件
- HDP2.0.6+hadoop2.2.0+eclipse(windows和linux下)调试环境搭建
- Dynamics CRM2013 任务列表添加自定义按钮
- 【Android 应用开发】Android开发 使用 adb logcat 显示 Android 日志
- 无依赖简单易用的Dynamics 365实体记录数计数器并能计算出FetchXml返回的记录数
- Python第7天
- tesseract安装及问题处理
- 转载 c# automapper 使用(一) https://www.cnblogs.com/caoyc/p/6367828.html
- NOIP模拟赛20180917 隐藏题目
- TypeError: atlas.getSpriteFrame is not a function
- php正则的使用
- java泛型学习(1)