Mutate() question

Hello, I was trying to create a separate column using the mutate function but could not see the column added at the end of the palmerpenguins package.

penguins %>%
  mutate(body_mass_kg=body_mass_g/1000)

The new column gets added on to the end of a wide tibble so that the display is truncated.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(palmerpenguins)
output <- penguins %>%
  mutate(body_mass_kg=body_mass_g/1000)
colnames(output)
#> [1] "species"           "island"            "bill_length_mm"   
#> [4] "bill_depth_mm"     "flipper_length_mm" "body_mass_g"      
#> [7] "sex"               "year"              "body_mass_kg"
output[9]
#> # A tibble: 344 × 1
#>    body_mass_kg
#>           <dbl>
#>  1         3.75
#>  2         3.8 
#>  3         3.25
#>  4        NA   
#>  5         3.45
#>  6         3.65
#>  7         3.62
#>  8         4.68
#>  9         3.48
#> 10         4.25
#> # ℹ 334 more rows

# or 
output$body_mass_kg
#>   [1] 3.750 3.800 3.250    NA 3.450 3.650 3.625 4.675 3.475 4.250 3.300 3.700
#>  [13] 3.200 3.800 4.400 3.700 3.450 4.500 3.325 4.200 3.400 3.600 3.800 3.950
#>  [25] 3.800 3.800 3.550 3.200 3.150 3.950 3.250 3.900 3.300 3.900 3.325 4.150
#>  [37] 3.950 3.550 3.300 4.650 3.150 3.900 3.100 4.400 3.000 4.600 3.425 2.975
#>  [49] 3.450 4.150 3.500 4.300 3.450 4.050 2.900 3.700 3.550 3.800 2.850 3.750
#>  [61] 3.150 4.400 3.600 4.050 2.850 3.950 3.350 4.100 3.050 4.450 3.600 3.900
#>  [73] 3.550 4.150 3.700 4.250 3.700 3.900 3.550 4.000 3.200 4.700 3.800 4.200
#>  [85] 3.350 3.550 3.800 3.500 3.950 3.600 3.550 4.300 3.400 4.450 3.300 4.300
#>  [97] 3.700 4.350 2.900 4.100 3.725 4.725 3.075 4.250 2.925 3.550 3.750 3.900
#> [109] 3.175 4.775 3.825 4.600 3.200 4.275 3.900 4.075 2.900 3.775 3.350 3.325
#> [121] 3.150 3.500 3.450 3.875 3.050 4.000 3.275 4.300 3.050 4.000 3.325 3.500
#> [133] 3.500 4.475 3.425 3.900 3.175 3.975 3.400 4.250 3.400 3.475 3.050 3.725
#> [145] 3.000 3.650 4.250 3.475 3.450 3.750 3.700 4.000 4.500 5.700 4.450 5.700
#> [157] 5.400 4.550 4.800 5.200 4.400 5.150 4.650 5.550 4.650 5.850 4.200 5.850
#> [169] 4.150 6.300 4.800 5.350 5.700 5.000 4.400 5.050 5.000 5.100 4.100 5.650
#> [181] 4.600 5.550 5.250 4.700 5.050 6.050 5.150 5.400 4.950 5.250 4.350 5.350
#> [193] 3.950 5.700 4.300 4.750 5.550 4.900 4.200 5.400 5.100 5.300 4.850 5.300
#> [205] 4.400 5.000 4.900 5.050 4.300 5.000 4.450 5.550 4.200 5.300 4.400 5.650
#> [217] 4.700 5.700 4.650 5.800 4.700 5.550 4.750 5.000 5.100 5.200 4.700 5.800
#> [229] 4.600 6.000 4.750 5.950 4.625 5.450 4.725 5.350 4.750 5.600 4.600 5.300
#> [241] 4.875 5.550 4.950 5.400 4.750 5.650 4.850 5.200 4.925 4.875 4.625 5.250
#> [253] 4.850 5.600 4.975 5.500 4.725 5.500 4.700 5.500 4.575 5.500 5.000 5.950
#> [265] 4.650 5.500 4.375 5.850 4.875 6.000 4.925    NA 4.850 5.750 5.200 5.400
#> [277] 3.500 3.900 3.650 3.525 3.725 3.950 3.250 3.750 4.150 3.700 3.800 3.775
#> [289] 3.700 4.050 3.575 4.050 3.300 3.700 3.450 4.400 3.600 3.400 2.900 3.800
#> [301] 3.300 4.150 3.400 3.800 3.700 4.550 3.200 4.300 3.350 4.100 3.600 3.900
#> [313] 3.850 4.800 2.700 4.500 3.950 3.650 3.550 3.500 3.675 4.450 3.400 4.300
#> [325] 3.250 3.675 3.325 3.950 3.600 4.050 3.350 3.450 3.250 4.050 3.800 3.525
#> [337] 3.950 3.650 3.650 4.000 3.400 3.775 4.100 3.775

Created on 2023-11-16 with reprex v2.0.2

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.