Search code examples
rpasteline-breaks

How to do a break line between (Character/Numeric) and (Character/Numeric) types in R


I have an easy question related to break lines in R.

I am trying to paste and I have problems to obtain break lines between the (Characters/Numeric).Remark that the values are contained in vectors (V1=81,V2=55,V3=25) I have tried this code:

cat(paste("Student Id:",V1,"Number of circuts:",V2,"Time (Minutes):",V3,sep='\n'))

But I obtain the values under the characters like this:

Student Id:
81
Number of circuts:
55
Time (Minutes):
25

Any idea to obtain the break line after the value of the vectors, the expected result would be like this:

Student Id: 81
Number of circuts: 55
Time (Minutes): 25

Solution

  • One way is to put the breakline \n manually and set sep="", e.g.

    cat(paste("Student Id:",V1,"\nNumber of circuts:",V2,"\nTime (Minutes):",V3,"\n", sep=''))
    
    #Student Id:81
    #Number of circuts:55
    #Time (Minutes):25
    

    Edit

    Quick remark. Your attempt was missing the fact that the separator sep is placed between each two arguments of the paste function.

    According to this, the breakline appears after both the names (e.g. Student Id) and the values (e.g. 81). That's how you got your output.