r

R - Add columns to dataframes in list by looping through elements in a vector

谁说胖子不能爱 提交于 2021-02-19 04:14:54
问题 I am working with several datasets that measure the same variables over many years. I am trying to add a year variable to each dataset, but more generally I want to loop through elements in a vector and add each as a new column in a list of dataframes. This question was similar to mine but I want to iteratively add each element in a vector to the corresponding dataframe as a new column: R - New variables over several data frames in a loop Here's sample data: year <- c(1:3) data1 <- data.frame

R - Add columns to dataframes in list by looping through elements in a vector

拟墨画扇 提交于 2021-02-19 04:13:50
问题 I am working with several datasets that measure the same variables over many years. I am trying to add a year variable to each dataset, but more generally I want to loop through elements in a vector and add each as a new column in a list of dataframes. This question was similar to mine but I want to iteratively add each element in a vector to the corresponding dataframe as a new column: R - New variables over several data frames in a loop Here's sample data: year <- c(1:3) data1 <- data.frame

Add labels to plot for specific values in R

三世轮回 提交于 2021-02-19 04:13:01
问题 I create a plot with the following dataset and I would like to add a label only for points flagged with a T in the "DisplayName" column. Probe Name DisplayName X Y bob1 A 0 53.989643 7935.185 bob2 B T 55.11423 7930.626 bob3 C 0 49.537724 6901.7715 bob4 D 0 57.280113 6687.0156 bob5 E T 7.5517325 840.3756 bob6 F 0 62.68943 6666.6665 bob7 G T 32.553364 3036.508 bob8 H 0 34.120102 2553.5354 bob9 I 0 127.54777 7818.89 My idea would be to use text() and which() to add the value of "Name" but I am

Merge two data frames considering a range match between key columns

浪子不回头ぞ 提交于 2021-02-19 04:11:49
问题 I am a beginner in programming in R. I am at the moment trying to retrieve some site names from a dataframe containing the X and Y coordinates and site names and copy them into a different dataframe with specific points. FD <- matrix(data =c(rep(1, 500), rep(0, 500), rnorm(1000, mean = 550000, sd=4000), rnorm(1000, mean = 6350000, sd=20000), rep(NA, 1000)), ncol = 4, nrow = 1000, byrow = FALSE) colnames(FD) <- c('Survival', 'X', 'Y', 'Site') FD <- as.data.frame(FD) shpxt <- matrix(c(526654.7

Merge two data frames considering a range match between key columns

烈酒焚心 提交于 2021-02-19 04:11:48
问题 I am a beginner in programming in R. I am at the moment trying to retrieve some site names from a dataframe containing the X and Y coordinates and site names and copy them into a different dataframe with specific points. FD <- matrix(data =c(rep(1, 500), rep(0, 500), rnorm(1000, mean = 550000, sd=4000), rnorm(1000, mean = 6350000, sd=20000), rep(NA, 1000)), ncol = 4, nrow = 1000, byrow = FALSE) colnames(FD) <- c('Survival', 'X', 'Y', 'Site') FD <- as.data.frame(FD) shpxt <- matrix(c(526654.7

Add labels to plot for specific values in R

╄→гoц情女王★ 提交于 2021-02-19 04:10:07
问题 I create a plot with the following dataset and I would like to add a label only for points flagged with a T in the "DisplayName" column. Probe Name DisplayName X Y bob1 A 0 53.989643 7935.185 bob2 B T 55.11423 7930.626 bob3 C 0 49.537724 6901.7715 bob4 D 0 57.280113 6687.0156 bob5 E T 7.5517325 840.3756 bob6 F 0 62.68943 6666.6665 bob7 G T 32.553364 3036.508 bob8 H 0 34.120102 2553.5354 bob9 I 0 127.54777 7818.89 My idea would be to use text() and which() to add the value of "Name" but I am

Add labels to plot for specific values in R

喜夏-厌秋 提交于 2021-02-19 04:09:50
问题 I create a plot with the following dataset and I would like to add a label only for points flagged with a T in the "DisplayName" column. Probe Name DisplayName X Y bob1 A 0 53.989643 7935.185 bob2 B T 55.11423 7930.626 bob3 C 0 49.537724 6901.7715 bob4 D 0 57.280113 6687.0156 bob5 E T 7.5517325 840.3756 bob6 F 0 62.68943 6666.6665 bob7 G T 32.553364 3036.508 bob8 H 0 34.120102 2553.5354 bob9 I 0 127.54777 7818.89 My idea would be to use text() and which() to add the value of "Name" but I am

Add labels to plot for specific values in R

大城市里の小女人 提交于 2021-02-19 04:08:44
问题 I create a plot with the following dataset and I would like to add a label only for points flagged with a T in the "DisplayName" column. Probe Name DisplayName X Y bob1 A 0 53.989643 7935.185 bob2 B T 55.11423 7930.626 bob3 C 0 49.537724 6901.7715 bob4 D 0 57.280113 6687.0156 bob5 E T 7.5517325 840.3756 bob6 F 0 62.68943 6666.6665 bob7 G T 32.553364 3036.508 bob8 H 0 34.120102 2553.5354 bob9 I 0 127.54777 7818.89 My idea would be to use text() and which() to add the value of "Name" but I am

Joining data.table with by argument

徘徊边缘 提交于 2021-02-19 04:02:12
问题 I have two data.table dx and dy dx <- data.table(a = c(1,1,1,1,2,2), b = 3:8) dy <- data.table(a = c(1,1,2), c = 7:9) I want to join dy to each row of dx , and below is the desired output data.table(plyr::ddply(dx, c("a", "b"), function(d) merge(d, dy, by = "a"))) a b c 1: 1 3 7 2: 1 3 8 3: 1 4 7 4: 1 4 8 5: 1 5 7 6: 1 5 8 7: 1 6 7 8: 1 6 8 9: 2 7 9 10: 2 8 9 However, I failed to make the output only using operation inside [] of data.table or merge ? I have tired merge(dx, dy, by = "a", all =

Pairwise partial correlation of a matrix, controlling by one variable

纵然是瞬间 提交于 2021-02-19 03:57:07
问题 I have a 100-column table for which I would like to run pairwise partial correlations, controlling by the 100th column's variable using the pcor.test function from the ppcor package. Is there any partial correlation function in R that I can use the returns something like rcorr , taking the pairwise correlations of the whole matrix but only controlling by one variable? 回答1: It sounds like for an n-column matrix you want to output a (n-1) x (n-1) matrix of the pairwise correlations of the first