Above data frame have 52 onservations and 8 variables and need to cahnge TRT01P and TRT01PN values and bind the dataset to actual data so total 104 observations and 8 varibales
IN 104 observation 52 observations TRT01p and TRT01PN has same values and other 52 observations TRT01p=X and TRT01pn=99
# use tidyverse libraries
library(tidyverse)
# create sample data frame
original <- data.frame( usubjid = 1:54,
trt01p = sample( letters, 54, replace = TRUE) ,
trt01pn = sample( 1:10, 54, replace = TRUE) )
# create temporay dataframe with new values
new <-
original %>% # use the orignal data frame
mutate( trt01p = "x", # change column values
trt01pn = 99 ) # change column values
# combine the two data frames into a new one
combined <-
bind_rows( original, new )
# remove old dataframes from memory, if no longer needed.
rm ( original, new )
It is a bit long for the small thing that you want to do, but I like this style because it is relatively clear what you are doing in what step.
Which means you hopefully can adjust the code easily to the more complicated things you want to do later
Also: When using tidyverse, the dypler cheat-sheets are a good help to figure out how to solve certain things.