当前位置:网站首页>melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化
melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化
2022-04-23 12:58:00 【qq_52813185】
melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化
# 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_52813185]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_52813185/article/details/124359319
边栏推荐
- Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
- 31. Next arrangement
- 【csnote】ER图
- 进程虚拟地址空间区域划分
- Common problems of unity (1)
- Try the server for one month for free, and attach the tutorial
- Jiachen chapter Genesis "inner universe" joint Edition
- 8 websites that should be known for product development to enhance work experience
- Wonderful review | the sixth issue of "source" - open source economy and industrial investment
- SSL certificate refund instructions
猜你喜欢
随机推荐
World Book Day: I'd like to recommend these books
(1) Openjuterpyrab comparison scheme
Byte warehouse intern interview SQL questions
Ad20 supplementary note 3 - shortcut key + continuous update
风尚云网学习-h5的input:type属性的image属性
SQL exercise question 1
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
Free and open source charging pile Internet of things cloud platform
The quill editor image zooms, multiple rich text boxes are used on one page, and the quill editor upload image address is the server address
Jupiter notebook installation
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
风尚云网学习-input属性总结
After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
Go language: passing slices between functions
The continuous construction of the Internet industry platform is not only able to collect traffic
Servlet监听器&过滤器介绍
安装nngraph
教你快速开发一个 狼人杀微信小程序(附源码)
使用Source Insight查看编辑源代码
Idea的src子文件下无法创建servlet







