[R] Vector of Numbers Not Output to Screen

Sarah Goslee sarah.goslee at gmail.com
Thu Jul 17 17:53:25 CEST 2014


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
>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list