当前位置:网站首页>Melt reshape decast long data short data length conversion data cleaning row column conversion
Melt reshape decast long data short data length conversion data cleaning row column conversion
2022-04-23 13:01:00 【qq_ fifty-two million eight hundred and thirteen thousand one h】
melt reshape decast Long data short data Long short conversion Data cleaning Transformation of ranks
# examples from 'tidyr' package
library(tidyr)
library(reshape2)
stocks = data.frame(
time = as.Date('2009-01-01') + 0:9,
X = rnorm(10, 0, 1),
Y = rnorm(10, 0, 2),
Z = rnorm(10, 0, 4)
)
head(stocks)

stocksm = stocks %>%
melt(id.vars = "time", variable.name = "stock", value.name = "price")
head(stocksm)
table(stocksm$stock)

stocksm %>% dcast(time ~ stock)

stocksm %>% dcast(stock ~ time)

# dcast and melt are complements
df = data.frame(x = c("a", "b"), y = c(3, 4), z = c(5, 6))

df %>%
dcast(z ~ x, value.var = "y") %>%
melt(id.vars = "z", variable.name = "x", value.name = "y", na.rm = TRUE)
# }




版权声明
本文为[qq_ fifty-two million eight hundred and thirteen thousand one h]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231258305842.html
边栏推荐
- leetcode:437. Path sum III [DFS selected or not selected?]
- How to click an object to play an animation
- pyqt5 将opencv图片存入内置SQLlite数据库,并查询
- 产品开发都应该知道的8个网站,增强工作体验
- Use compressorjs to compress pictures, optimize functions, and compress pictures in all formats
- SSM框架系列——Junit单元测试优化day2-3
- STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
- Unlock openharmony technology day! The annual event is about to open!
- 软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
- 31. 下一个排列
猜你喜欢

Synchronously update the newly added and edited data to the list

Use compressorjs to compress pictures, optimize functions, and compress pictures in all formats

Huawei cloud MVP email

The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!

Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)

SSM framework series - annotation development day2-2

Kubernetes 入門教程
![Packet capturing and sorting -- TCP protocol [8]](/img/ae/4957a997af725a1bf3f61cb24fc717.png)
Packet capturing and sorting -- TCP protocol [8]

Free and open source intelligent charging pile SaaS cloud platform of Internet of things

Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
随机推荐
Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
Golang realizes regular matching: the password contains at least one digit, letter and special character, and the length is 8-16
If you were a golang interviewer, what questions would you ask?
Translation of multi modal visual tracking: review and empirical comparison
Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
【蓝桥杯】4月17日省赛刷题训练(前3道题)
SSL certificate refund instructions
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
Mysql8 installation
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
Object.keys后key值数组乱序的问题
Huawei cloud MVP email
数据库中的日期时间类型
Pytorch: a pit about the implementation of gradreverselayer
精度、速度完美平衡,最新图像分割SOTA模型重磅发布!!!
Softbank vision fund entered the Web3 security industry and led a new round of investment of US $60 million in certik
The project file '' has been renamed or is no longer in the solution, and the source control provider associated with the solution could not be found - two engineering problems
Importerror after tensorflow installation: DLL load failed: the specified module cannot be found, and the domestic installation is slow
Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
The continuous construction of the Internet industry platform is not only able to collect traffic