You can do it like this using the Tidyverse and the tidyr function spread:
# Here's your example data
example_data <- data.frame(Date = "Sept",
TOTAL = "18 3",
Type = LETTERS[1:4],
AMT = c(0.5, 0.25, 0.75, 1.5),
stringsAsFactors = FALSE)
# Load Tidyverse and "transpose" using tidyr:: spread
suppressPackageStartupMessages(library(tidyverse))
transposed_data <- example_data %>%
spread(key = "Type", value = "AMT")
#Print
print(transposed_data)
#> Date TOTAL A B C D
#> 1 Sept 18 3 0.5 0.25 0.75 1.5
thank you for your help, its actually Sept 18 (date) and total is 3. Apologies if it wasn't clear. I don't think it should make a difference.
But, when I try to apply it to my data (it is an excel import). It says Error in example_data %>% spread(key = "Type", value = "AMT"): could not find function "%>%"
This is one reason it's helpful to use the reprex package (short for reproducible example). It helps ensure we're working with/looking at the same stuff.
If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.