I am solving a task for my online R course. I have the following vector:
L<-list(Surname=c("Javi","James","Thomas","Arjen","David","Arturo","Robert"),
Number=c(8,11,25,10,27,23,9),
Name=c("Martinez","Rodriguez","Mueller","Robben","Alaba","Vidal","Lewandowski")
The task is to output the following result using the paste0()-function:
[1] "8:Javi Martinez" "11:James Rodriguez" "25:Thomas Müller"
[4] "10:Arjen Robben" ...
Using the function:
paste0(L$Nummer,L$Vorname,L$Name)
results in:
[1] "8JaviMartinez" "11JamesRodriguez" "25ThomasMueller"
[4] "10ArjenRobben"
I've tried to use the sep and the collapse arguments, but both of them only affect the end of the elements, for example 8JaviMartinez-, when using sep="-".
You can try this, I am assuming there is no space before and after colon(:), With the restriction of not using paste, you can choose paste0 with spaces in between.
paste0(L$Number,":",L$Surname," ",L$Name)
However, I am not sure, If there are any further restrictions that are there to solve this problem.
Output:
> paste0(L$Number,":",L$Surname," ",L$Name)
[1] "8:Javi Martinez" "11:James Rodriguez"
[3] "25:Thomas Mueller" "10:Arjen Robben"
[5] "27:David Alaba" "23:Arturo Vidal"
[7] "9:Robert Lewandowski"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With