Going from long to wide

  • Comments posted to this topic are about the item Going from long to wide

  • Good reminder, thanks Steve

    Rusty is not the word....

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • A new one for me, still not sure I completely get how it works. Need to play with it a bit.

  • The choice of "4 columns 3 rows" does not appear to be correct, but it is the closest, so this is why I chose it. The correct choice should probably read 5 columns 3 rows. The original dataframe named speaking has 4 columns and 9 rows. Pivoting it produces 3 rows and 5 columns: original ID and Name and also 3 columns for years (2015, 2016 and 2017). The events wrap under the years becoming cell values. Interestingly enough, the explanation includes the entire dataframe spelled out. It has 5 columns, as expected (not 4), plus the index of course. Calling str on it clearly states that the dataframe has 5 columns, not 4:

    > str(widespeaking)
    'data.frame': 3 obs. of 5 variables:
    $ ID : int 1 2 3
    $ Name: Factor w/ 3 levels "Steve","Grant",..: 1 2 3
    $ 2015: num 32 24 34
    $ 2016: num 18 32 32
    $ 2017: num 32 31 19

    Asking for column names returns a vector with 5 items:

    > colnames(widespeaking)
    [1] "ID" "Name" "2015" "2016" "2017"

    I am not sure what, if anything, is wrong with my understanding. It really looks like the dataframe has 5 columns, not 4.

    Oleg

  • Ah, I didn't think the ID was counted, but as it's in every dataframe. I'll correct that.

    Renaming the variable as well.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply