I would like to create a string like JSON format using the sprintf function. I use this code:
sprintf
elements_list = sprintf('{"id":"%s", "top": "%s", }', 5, 4)
But the result when I print the string is like this:
"{"id":"5","top":"4"}"
with "" character everywhere, any help?
""
Thanks!
This should work - you don't need all the double-quotes inside the expression:
elements_list = sprintf('{id:%s top: %s}', 5, 4) elements_list # [1] "{id:5 top: 4}"
2.1m questions
2.1m answers
60 comments
57.0k users