[R] Vector of Numbers Not Output to Screen

David Winsemius dwinsemius at comcast.net
Fri Jul 18 01:32:26 CEST 2014


On Jul 17, 2014, at 9:27 AM, Rui Barradas wrote:

> Hello,
> 
> Also, unlike what the op says, if statements are functions, explaining the behavior he got.

I'm not sure that is correct. The help page says if() is a control-construct. I think the function is actually "{"

> {rnorm(10); rpois(10, 3)}
 [1] 5 3 5 5 7 3 4 4 0 5

See

?Paren

-- 
David.
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Em 17-07-2014 16:53, Sarah Goslee escreveu:
>> Hi,
>> 
>> You can get the behaviour you want using the print() command:
>> 
>> if(1 < 2)
>> {
>>   x<-rnorm(100)
>>   y <- rpois(10, 5)
>>   print(head(x))
>>   print(head(y))
>> }
>> 
>> 
>> Sarah
>> 
>> On Thu, Jul 17, 2014 at 2:00 AM, Dario Strbenac
>> <dstr7320 at uni.sydney.edu.au> wrote:
>>> Hello,
>>> 
>>> I have a block of code that has two head calls at the end, but only the second is shown on screen. If I manually execute the statement which is not showing, it works. I thought that if statements are not functions. It is behaving as one.
>>> 
>>>> if(1 < 2)
>>> + {
>>> +   x<-rnorm(100)
>>> +   y <- rpois(10, 5)
>>> +   head(x)
>>> +   head(y)
>>> + }
>>> [1] 4 4 5 4 8 3
>>>> 
>>>> head(x)
>>> [1] -1.89083874  0.42442102  0.96114276  0.48004716  1.94358108 -0.02654324
>>> 
>>>> sessionInfo()
>>> R version 3.1.1 (2014-07-10)
>>> Platform: i386-w64-mingw32/i386 (32-bit)
>>> 
>>> locale:
>>> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
>>> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
>>> [5] LC_TIME=English_United States.1252
>>> 
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>> 
>> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list