I am trying take a valuable from the rows and make them into columns in are.
Thank you all for your assistance
I am trying take a valuable from the rows and make them into columns in are.
Thank you all for your assistance
What you're trying to do is pivot the data into wide shape this can be easily achieved with the tidyr::pivot_wider
function, all you need to do is specify the columns from where the values will be taken and columns that contain the name for those values:
library(tidyverse)
df %>% pivot_wider(names_from=Position, values_from=count)
# A tibble: 4 x 4
Unit fulltime parttime volunteer
<fct> <int> <int> <int>
1 hospital 20 100 50
2 Police 20 NA NA
3 police NA 5 10
4 fire 20 1 5
read.table(text="Unit,Position,count
hospital,fulltime,20
hospital,parttime,100
hospital,volunteer,50
Police,fulltime,20
police,parttime,5
police,volunteer,10
fire,fulltime,20
fire,parttime,1
fire,volunteer,5", header=T, sep=',') -> df
One thing to keep in mind is when asking a question you need to provide the data in code form not in screenshots, one handy function to achieve this is the dput
function after running dput(data.f)
paste it to your question.