Creating new dataframe with averages


I've been extracting anuran acoustic data using the program RavenPro v1.6 and am trying to summarise the data in R. Multiple calls were analysed in each bout, meaning there are several data points for each call recording. I've manage to create a new data frame in R with the averages, but when I do it puts all my categorical data to 'NA', as with some of the numerical data. Below is the R code I used to do this. I was wondering if anyone has any insight into how I can create the new data frame with all my numerical values averaged and doesn't remove my categorical information? Thanks in advance!

Averaging the data and creating new dataframe

acoustic_summary = aggregate(data2, by=list(data2$FileName), FUN=mean, na.rm=TRUE)


I actually have some experience with RavenPro :slight_smile: . Can you provide some example data with your code? That will just make it much easier to troubleshoot and see what's happening. See here on how to make a reprex: FAQ: How to do a minimal reproducible example ( reprex ) for beginners

Great! Thanks for replying so quickly Grey. I've attached some example data and the R code.

I figure it's best to start at the beginning. The data began as just txt files. I've imported all the txt files, added the lineage to the data frame and stacked all the txt files. The final data frame I'm trying to get will have single averaged values for all factors while still keeping the categorical values. I was unsure of how to keep the inter-call and call data separate, so initially I just removed all inter-call data, but since you have experience with RavenPro you may have a better method?

Stacking Data frame####

list_of_files <- list.files(path = home, recursive = TRUE,
pattern = "\.txt$",
full.names = F)
DT <- rbindlist(sapply(list_of_files, fread, simplify = FALSE),
use.names = TRUE, idcol = "FileName", fill = TRUE)

binding data

data = merge(id, DT, by = 'FileName')
data1 = merge(id, DT, by = 'FileName')

Replacing N/A values in dataframe with NA

data1[data1 == "A"] <- "XXX"
data1[data1 == "N/A"] <- ""
data1[data1 == ""] <- NA
data1[data1 == ""] <- NA

Removing all intercall data

toBeRemoved<-which(data1$Type=="intercall", data1$Type=="inercall")

Averaging the data and creating new dataframe

acoustic_summary = aggregate(data2, by=list(data2$FileName), FUN=mean, na.rm=TRUE)

A screenshot of the data is not too useful to work with. Can you provide a copy pasteable version of the data? Something like datapasta makes it very easy.

Apologies but I'm unfamiliar with the package datapasta, and unfortunately I can't upload the spreadsheet I have made in excel. Would it be possible to send it to you via email?

No worries. Here is an example here: . You can just copy the data from excel and paste it into your R script with it. Let me know if you don't get it to work.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.