Here’s a shorter way, taking advantage of the way unlist
deals with names:
library(dplyr)
df1 %>% group_by(Name) %>% do(as_tibble(t(unlist(.[2]))))
# # A tibble: 2 x 4
# # Groups: Name [2]
# Name MedName1 MedName2 MedName3
# <chr> <chr> <chr> <chr>
# 1 name1 atenolol 25mg aspirin 81mg sildenafil 100mg
# 2 name2 atenolol 50mg enalapril 20mg <NA>
Related Contents:
- How to reshape data from long to wide format
- Reshaping data.frame from wide to long format
- Reshaping multiple sets of measurement columns (wide format) into single columns (long format)
- Reshape multiple value columns to wide format
- ggplot with 2 y axes on each side and different scales
- Replacing NAs with latest non-NA value
- Filter data.frame rows by a logical condition
- Count number of rows within each group
- How to add leading zeros?
- How to create a consecutive group number
- Add legend to ggplot2 line plot
- Remove rows with all or some NAs (missing values) in data.frame
- Calculate group mean, sum, or other summary stats. and assign column to original data
- Use dynamic name for new column/variable in `dplyr`
- Order discrete x scale by frequency/value
- Find complement of a data frame (anti – join)
- Split delimited strings in a column and insert as new rows [duplicate]
- Subset data frame based on number of rows per group
- Combine a list of data frames into one data frame by row
- Convert continuous numeric values to discrete categories defined by intervals
- Error in if/while (condition) {: missing Value where TRUE/FALSE needed
- Unique combination of all elements from two (or more) vectors
- How to split a data frame?
- Counting the number of elements with the values of x in a vector
- Formatting Decimal places in R
- Plot two graphs in same plot in R
- Only read selected columns
- Error: unexpected symbol/input/string constant/numeric constant/SPECIAL in my code
- Cleaning up factor levels (collapsing multiple levels/labels)
- Elegant way to check for missing packages and install them?
- ggplot’s qplot does not execute on sourcing
- Subset / filter rows in a data frame based on a condition in a column
- Vectorized IF statement in R?
- How does one reorder columns in a data frame?
- Understanding the order() function
- Error in : target of assignment expands to non-language object
- What are the differences between “=” and “
- What are the main differences between R data files?
- What’s the biggest R-gotcha you’ve run across?
- Logical operators (AND, OR) with NA, TRUE and FALSE
- How to sort a character vector where elements contain letters and numbers?
- How do I install a package that has been archived from CRAN?
- Get filename without extension in R
- What is the difference between = and ==?
- What is the difference between = and == in R?
- How should I deal with “‘someFunction’ is not an exported object from ‘namespace:somePackage'” error? [closed]
- duplicate ‘row.names’ are not allowed error
- Should I use a data.frame or a matrix?
- R: How to split a data frame into training, validation, and test sets?
- Is there anything wrong with using T & F instead of TRUE & FALSE?