I have a dataframe (dimensions = 1134*14) and would like to copy part of the data values from one column to another column in the same dataframe in R for further reshaping the data for plotting purpose. I would like to copy the data values from row 371 to row 1134 from(Aggregate to Cluster column, and another from sub_aggregate to cluster_location column)
Please assist me how to copy data from a specific row.
Thank you,
Toufiq
Example of the input and expected output data are provided below:
Input
dput(df_1) structure(list(position = c("A28.1", "A34.1", "A38.2", "A1.19", "A37.10", "A37.2", "A37.11", "A1.32", "A35.6", "A8.35", "A8.36", "A8.37", "A8.38", "A8.39", "A8.40", "A8.41", "A8.42", "A8.9"), Set = c("M10.1", "M10.3", "M10.4", "M11.1", "M11.2", "M11.3", "M11.4", "M12.1", "M12.10", "", "", "", "", "", "", "", "", ""), Group_A = c(95.23809524, -63.15789474, 33.33333333, 0, -23.33333333, -26.31578947, -20.83333333, 17.39130435, -67.34693878, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_B = c(0, 36.84210526, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_C = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_D = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_E = c(76.19047619, -26.31578947, 0, 0, 0, 0, 0, 19.56521739, -34.69387755, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_F = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA), Cluster = c("A28", "A34", "A38", "A1", "A37", "A37", "A37", "A1", "A35", "", "", "", "", "", "", "", "", ""), Cluster_location = c(1L, 1L, 2L, 19L, 10L, 2L, 11L, 32L, 6L, NA, NA, NA, NA, NA, NA, NA, NA, NA), Function = c("Biological processes", "Molecular functions", "cellular components", "cellular components", "cellular components", "cellular components", "Biological processes", "Biological processes", "TBD", "", "", "", "", "", "", "", "", ""), Aggregate = c("", "", "", "", "", "", "", "", "", "A8", "A8", "A8", "A8", "A8", "A8", "A8", "A8", "A8"), sub_aggregate = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 9L)), class = "data.frame", row.names = c(NA, -18L)) Expected Output
dput(df_2) structure(list(position = c("A28.1", "A34.1", "A38.2", "A1.19", "A37.10", "A37.2", "A37.11", "A1.32", "A35.6", "A8.35", "A8.36", "A8.37", "A8.38", "A8.39", "A8.40", "A8.41", "A8.42", "A8.9"), Set = c("M10.1", "M10.3", "M10.4", "M11.1", "M11.2", "M11.3", "M11.4", "M12.1", "M12.10", "", "", "", "", "", "", "", "", ""), Group_A = c(95.23809524, -63.15789474, 33.33333333, 0, -23.33333333, -26.31578947, -20.83333333, 17.39130435, -67.34693878, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_B = c(0, 36.84210526, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_C = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_D = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_E = c(76.19047619, -26.31578947, 0, 0, 0, 0, 0, 19.56521739, -34.69387755, NA, NA, NA, NA, NA, NA, NA, NA, NA), Group_F = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, NA), Cluster = c("A28", "A34", "A38", "A1", "A37", "A37", "A37", "A1", "A35", "A8", "A8", "A8", "A8", "A8", "A8", "A8", "A8", "A8"), Cluster_location = c(1L, 1L, 2L, 19L, 10L, 2L, 11L, 32L, 6L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 9L), Function = c("Biological processes", "Molecular functions", "cellular components", "cellular components", "cellular components", "cellular components", "Biological processes", "Biological processes", "TBD", "", "", "", "", "", "", "", "", ""), Aggregate = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), sub_aggregate = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), class = "data.frame", row.names = c(NA, -18L)) https://stackoverflow.com/questions/66654469/copy-data-from-one-column-to-another-column-from-a-specific-row-in-r-dataframe March 16, 2021 at 07:36PM
没有评论:
发表评论