当前位置:网站首页>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
边栏推荐
- SSM framework series - data source configuration day2-1
- Byte jump 2020 autumn recruitment programming question: quickly find your own ranking according to the job number
- Synchronously update the newly added and edited data to the list
- 8 websites that should be known for product development to enhance work experience
- Kubernetes 入門教程
- 21 天学习MongoDB笔记
- SSM framework series - JUnit unit test optimization day2-3
- 梳理网络IP代理的几大用途
- [Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
- Golang implements MD5, sha256 and bcrypt encryption
猜你喜欢

内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘

XinChaCha Trust SSL Organization Validated

31. Next arrangement

Fashion cloud learning - input attribute summary

SSM framework series - data source configuration day2-1

31. 下一个排列

CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
![[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)](/img/7d/23e2a611bc6a0d0239abdc79e2e8cf.png)
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)

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

JMeter operation redis
随机推荐
5 free audio material websites, recommended collection
有趣的IDEA插件推荐,给你的开发工作增添色彩
Go language array operation
22. Bracket generation
Object.keys后key值数组乱序的问题
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
51 single chip microcomputer stepping motor control system based on LabVIEW upper computer (upper computer code + lower computer source code + ad schematic + 51 complete development environment)
将opencv 图片转换为字节的方式
Summary of JVM knowledge points - continuously updated
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
SSM框架系列——注解开发day2-2
CVPR 2022 & ntire 2022 | the first transformer for hyperspectral image reconstruction
JDBC connection pool
Hanlp word splitter (via spark)
Keyword interpretation and some APIs in RT thread
XinChaCha Trust SSL Organization Validated
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
Kubernetes 入門教程
There is no need to crack the markdown editing tool typora
Calculate the past date and days online, and calculate the number of live days