Problems using tidyr separate on "|"

Problems using tidyr separate on "|"

By : Malcolm Googe
Date : October 20 2020, 08:10 AM
To fix this issue I have an object lncRNA_lengths like this: , This should do it, first make fake data:
code :
df <- data.frame(tx_name = "align_id:155048|asmbl_67",length = 205, type = "lncRNA")
df <- separate(df, col = tx_name, sep = "\\|", into = c("ID", "asmbl"))

Share : facebook icon twitter icon
Separate a column into multiple columns using tidyr::separate with sep=""

Separate a column into multiple columns using tidyr::separate with sep=""

By : New Human
Date : March 29 2020, 07:55 AM
I hope this helps . , You could do this with extract from tidyr
code :
extract(df, sequence, into=paste0('V', 1:5), '(.)(.)(.)(.)(.)')
#  category V1 V2 V3 V4 V5
#1        X  A  A  T  .  G
#2        Y  C  C  G  -  T
df %>% 
   mutate(sequence=gsub('(?<=.)(?=.)', ',', sequence, perl=TRUE)) %>% 
   separate(sequence, into=paste0('V', 1:5), sep=",")
#  category V1 V2 V3 V4 V5
#1        X  A  A  T  .  G
#2        Y  C  C  G  -  T
setnames(cSplit(df, 'sequence', '', stripWhite=FALSE),
             2:6, paste0('V', 1:5))[]
#   category V1 V2 V3 V4 V5
#1:        X  A  A  T  .  G
#2:        Y  C  C  G  -  T
Separate a String using Tidyr's "separate" into Multiple Columns and then Create a New Column with Counts

Separate a String using Tidyr's "separate" into Multiple Columns and then Create a New Column with Counts

By : Harshal Chordiya
Date : March 29 2020, 07:55 AM
I wish this help you So I have the basic dataframe below which contains long strings separated by a comma.I used Tidyr's "separate" to create new columns. , We can try with str_count
code :
df %>%
  separate(Goal,paste0("Goal", 1:4), sep=",", remove=FALSE) %>% 
  mutate(Count = str_count(Goal, ",")+1) %>%
#  Name             Goal1          Goal2             Goal3         Goal4 Count
#  <chr>             <chr>          <chr>             <chr>         <chr> <dbl>
#1  John Go back to school Learn to drive     Learn to cook          <NA>     3
#2 Chris Go back to school      Get a job Learn a new Skill Learn to cook     4
#3  Andy    Learn to drive  Learn to Cook              <NA>          <NA>     2
"'into' is missing" during separate column (tidyr)

"'into' is missing" during separate column (tidyr)

By : Rafael Lara
Date : March 29 2020, 07:55 AM
around this issue Separate requires an argument into in the function. These should be the names of the variables to create. Your call does does not include the argument.
An adapted example from the help file:
code :
df <- data.frame(x = c(NA, "a.b", "a.d", "b.c"))
separate(data = df, col = x, into = c("A", "B"))
     A    B
1 <NA> <NA>
2    a    b
3    a    d
4    b    c
df <- data.frame(id = c(1,2,3), 
             author = c("name1; name2; name3", 
                        "name1; name2", "name1"))

  id              author
1  1 name1; name2; name3
2  2        name1; name2
3  3               name1
str_count(df$author, ";")
[1] 2 1 0
max_n_authors <- max(str_count(df$author, ";")) + 1
[1] 3
paste("author", 1:max_n_authors)
[1] "author 1" "author 2" "author 3"
df <- df %>% 
    separate(., col = author, into = paste("author", 1:max_n_authors))
Warning message:
Too few values at 2 locations: 2, 3 
  id author 1 author 2 author 3
1  1    name1    name2    name3
2  2    name1    name2     <NA>
3  3    name1     <NA>     <NA>
Specify separator character in "separate" function from package tidyr

Specify separator character in "separate" function from package tidyr

By : user2731025
Date : March 29 2020, 07:55 AM
it helps some times I have a tibble with a column containing strings in the format XX_YY_ZZ. I need to separate the column into two different columns using the first underscore as a separation character. , 1) Specify extra = "merge"
code :
d %>% 
  separate(var, into=c("newcol1", "newcol2"), extra = "merge", sep = "_")
d %>% 
  mutate(var = sub("_", "__", var)) %>% 
  separate(var, into=c("newcol1", "newcol2"), sep = "__")
d %>%
  mutate(newcol1 = sub("_.*", "", var), newcol2 = sub(".*?_", "", var), var = NULL)
What is the meaning of " \\." in tidyr::separate?

What is the meaning of " \\." in tidyr::separate?

By : user3636279
Date : March 29 2020, 07:55 AM
wish help you to fix your issue It would be easier to understand if you run the code step by step.
gather brings the data in long format with column key with column names and column value with values of those columns
code :

iris %>% gather(key, Value, -Species) %>%  head

#  Species          key Value
#1  setosa Sepal.Length   5.1
#2  setosa Sepal.Length   4.9
#3  setosa Sepal.Length   4.7
#4  setosa Sepal.Length   4.6
#5  setosa Sepal.Length   5.0
#6  setosa Sepal.Length   5.4
iris %>%
  gather(key, Value, -Species) %>%
  separate(key, c("Part", "Measure"), "\\.") %>% head

#  Species  Part Measure Value
#1  setosa Sepal  Length   5.1
#2  setosa Sepal  Length   4.9
#3  setosa Sepal  Length   4.7
#4  setosa Sepal  Length   4.6
#5  setosa Sepal  Length   5.0
#6  setosa Sepal  Length   5.4
Related Posts Related Posts :
  • R 'cowplot' neatly produce gridded plot with shared (common) legends and unique legends
  • Repeat R script for many times and save results to text file
  • How to negative lookbehind for special characters
  • data.table inner join produces error when no match is found
  • Create a new column base on existing column, but row above
  • Is there a way to visualize the process of source() in RStudio?
  • google places api consumes 10 request but I am doing only 1
  • Statistical mode of a categorical variable in R (using mlv)
  • Using for-loop to mutate a data.frame in r
  • Make plot with regression line for mixed model
  • Shortcut to select matces cases in R studio
  • vectoriced norm/matrix multiplication
  • Negative log10 transformation in R
  • Plot data with duplicate points
  • Visualizing crosstab tables with a plot in R - changing colours
  • How to manually modify automated numbers and labels in plot
  • How can I follow any redirections of a url in R?
  • Add jitter to box plot using markers in plotly
  • Adding an extra item to the legend
  • ggplot fills in data in the wrong order
  • Convert list to data frame
  • R: filtering by list(s) of strings and returning all results that start with the content of the lists
  • R:How to attach parts of a data frame with different headers and/or an overflowing piece of the dat frame
  • How to use 'par' for manipulating plot margins?
  • Can dplyr::case_when return mix of NAs and non-NAs?
  • Text preprocessing and topic modelling using text2vec package
  • Uploading multiple files in Shiny, process the files, rbind the results and return a download
  • R levelplot: color green-white-red (white on 0) according to one variable, but show the values of another variable
  • Why [i] doesn't point to the starting point in a vector
  • In R after generating a mvrnorm distribution, Y, what does Y[,1] do?
  • expand a data frame to have as many rows as range of two columns in original row
  • Getting started with R and CFA
  • Re order x-axis in ggplot so time goes from 12AM to 11PM in R
  • R - Automatically stack every nth column of a data frame and save them as new objects
  • How to format dplyr output in R into doubles (or other workable format)?
  • Dataframe to matrix conversion using tapply turns zeros to NAs
  • Smallest multiple of 1:20 - How can I make it quicker?
  • How to specify the size of a graph in ggplot2 independent of axis labels
  • How can I find the number of a vector's elements in another vector?
  • ROC curve from train/test set in caret R package
  • Random Forest for a mixture of categorical,numeric and "unwanted" variables which include missing values
  • extract certain data from multiple excel files with R
  • Matrix with counts of wins and losses between methods in R
  • Grouping string variables from a dataframe by best string match to make subsets
  • Reorder does not work after adding second geom_points
  • cover POS data formate to the one can apply Arules (Apriori)
  • Matching values between data frames based on overlapping dates
  • Grouped bar chart turns into stacked bar chart ggplot
  • R: How to fill in NA Values within a Column based on grouping?
  • Two action buttons, but only the first one, that is written in the server file, works?
  • Barchart grouped by variable both count up to 100 percent
  • Converting time in R to 24 hours
  • R - Web scrapping and downloading multiple zip files and save the files without overwriting
  • Find month and year inside string
  • Append multiple csv files into one file using R
  • Use `purrr::map` with k-means
  • R - 'data' is not an exported object from 'namespace:my_package'
  • Sum vector with number by dinamic intervals without looping
  • Issues with ave function in R: error "cannot allocate vector of size 419 kb."
  • Shiny system call with continuous updates
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org