简体   繁体   English

数据整理以映射录音中音符的时间和频率

[英]Data wrangling to map timing and frequency of the notes in a recording

I have a dataset having 216 sound recording files represented by the start and end timing (in seconds) and the respective frequencies of the notes sung by male and female birds:我有一个数据集,其中包含 216 个录音文件,由开始和结束时间(以秒为单位)以及雄鸟和雌鸟唱出的音符的各自频率表示:

note笔记 sound.files声音文件 start开始 end结尾 freq频率 sex性别
1 1 a一个 2.7 2.7 3.2 3.2 1.55 1.55 f F
2 2 a一个 3.2 3.2 3.6 3.6 1.17 1.17 m
3 3 a一个 3.6 3.6 4.0 4.0 1.17 1.17 f F
4 4 a一个 3.9 3.9 4.3 4.3 0.89 0.89 m
5 5 a一个 4.3 4.3 4.4 4.4 0.79 0.79 f F
1 1 b b 1.9 1.9 2.3 2.3 1.45 1.45 f F
2 2 b b 2.4 2.4 2.7 2.7 3.71 3.71 m
3 3 b b 2.6 2.6 3.1 3.1 1.36 1.36 f F
4 4 b b 3.1 3.1 3.4 3.4 3.62 3.62 m
5 5 b b 3.9 3.9 4.4 4.4 0.79 0.79 m
6 6 b b 4.5 4.5 4.6 4.6 1.17 1.17 f F

I require to transform the data in a long format with time-mapped frequency values of male and female birds for each recording, eg:我需要将数据转换为长格式,每次记录的雄性和雌性鸟类的时间映射频率值,例如:

sound.files声音文件 time时间 m f F
a一个 2.7 2.7 0 0 1.55 1.55
a一个 2.8 2.8 0 0 1.55 1.55
a一个 2.9 2.9 0 0 1.55 1.55
a一个 3.0 3.0 0 0 1.55 1.55
a一个 3.1 3.1 0 0 1.55 1.55
a一个 3.2 3.2 1.17 1.17 0 0
a一个 3.3 3.3 1.17 1.17 0 0

I tried the following code but it did not work and running into an error:我尝试了以下代码,但它没有工作并遇到错误:

Error: Problem with summarise() input ..1 .错误: summarise()输入..1有问题。 x object 'freq' not found:未找到 x 对象“频率”:

code:代码:

cum_call1 <- function(start,end,freq){
  data.frame(time = seq(start,end,by = .1), calling = 1, freq= mean(freq))
}

cum_expand1 <- function(start,end){
  data.frame(time = seq(start,end,by = .1))
}

data.frame$start <- round(data.frame$start,1)
data.frame$end <- round(data.frame$end,1)


duet_call <- data.frame %>% 
  group_by(sound.files,sex,note) %>% 
  summarise(cum_call1(start,end,freq)) %>% 
  ungroup() %>% 
  select(-note)

Is there any right/better way to go about it?有什么正确/更好的方法吗? Any suggestions are welcome!欢迎任何建议! Thanks in advance!提前致谢!

Not base R but the pivot_wider function from one of the tidyverse packages should help.不是基于 R,而是来自 tidyverse 包之一的 pivot_wider 函数应该有所帮助。 You're pivoting the column to be wider not longer as one column (sex) is becoming two.(m,f)当一列(性别)变成两列时,您正在将列旋转得更宽而不是更长。(m,f)

library(tidyverse)

pivot_wider(data,names_from=sex,values_from=freq)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM