Re: [R] correlation by factor

2021-07-27 Thread Rui Barradas
Hello, And here are three more ways. I will put the data, corrected in Bert's post, in a data.frame. R <- c(1,8,3,6,7,2,3,7,2,3,3,4,3,7,3) Day <- c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3) Freq <- paste0("a", rep(1:5,3)) df1 <- data.frame(R, Day, Freq) # Base R, as for the function, see Bert's post sa

Re: [R] correlation by factor

2021-07-27 Thread Bert Gunter
Well, first of all, your example is messed up. You missed the "c" in front of the ( in Freq <-; and all of the Freq entries need to be enclosed in quotes for proper syntax. A simpler way to do it is just to use paste() and rep(): Freq <- paste0("a", rep(1:5,3)) (If you are not familiar with such "

[R] correlation by factor

2021-07-27 Thread Marlin Keith Cox
I am having problems making a correlation/association between two variables by a factor. In the case below, I need to know the correlation between R and Day at each frequency (a1-a5). Each frequency would have a corresponding correlation between R and day. I have found a lm function that is simil