I am generating an input file for software. I ran into an inconsistency in paste0() function. Here are my example list of names.
vars <- c("1234_AS_SA1_PCNS","2345_AS_SA2_UDA", "3823_AS_SA3_CL")
I would like to print this:
"Equal = (1234_AS_SA1_PCNS, Slope[0]),
(2345_AS_SA2_UDA, Slope[0]),
(3823_AS_SA3_CL, Slope[0]);"
I tried this but it did not do the job. SOmehow, "Equal" gets to the end.
paste0("Equal = ",
for(i in 1:length(vars)) {
Equal <- paste0("(",vars[i], ", Slope[0])", ",")
print(Equal)
})
[1] "(1234_AS_SA1_PCNS, Slope[0]),"
[1] "(2345_AS_SA2_UDA, Slope[0]),"
[1] "(3823_AS_SA3_CL, Slope[0]),"
[1] "Equal = "
This function does not employ ","s correctly as well as a ";" at the end.
Any thoughts? Thanks.
cat(paste0("Equal = ", paste("(", vars, ", Slope[0])", collapse=", ", sep="")))