R correlation based on values in a column -


say have data of following type

day dev val 1   1   ? 1   2   ? 1   3   ? 2   2   ? 2   1   ? 2   3   ? 3   1   ? 3   3   ? 4   1   ? 4   2   ? 4   3   ? 

and calculate correlation between values (val, ? value number) read devices (dev) along days, if value of device missing in day skip day (for example device 2 missing in day 3). can think of creating 3 choose 2 tables indexed day has columns pairs of devices , doing correlation each table. however, coding heavy. there elegant way perform this?

my code using way explained above this, assuming data in df_0:

df <- data.frame(day=integer()) # lets create data frame day values (currentdev in unique(df_0$dev)){   df_val <- df_0 %>%     filter(dev == currentdev) %>%     select(c(day,val))   # rename column before merging   names(df_temp)[names(df_temp) == "val"] <- paste0('dev_',currentdev)   # merge   df <- merge(x=df, y=df_temp, = "day", = true) } view(df)  

then df can used calculating correlation. sure there must better way.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -