In data frame how to spilt strings into values

0 votes

Here is a data frame which consist of character variable "SAP"

 ID                  VAR
1  4 SAP1\r\nSAP2\r\nSAP8
2  5         SAP2\r\nSAP5

I would like to split the variable -\r\n and obtain the desired dataframe:

  ID  VAR
1  4 SAP1
2  4 SAP2
3  4 SAP8
4  5 SAP2
5  5 SAP5
Apr 4, 2018 in Data Analytics by DataKing99
• 8,240 points
237 views

2 answers to this question.

0 votes


We can easily do this with separate_rows() function

library(tidyr)
separate_rows(df, VAR, sep='\\s+')
answered Apr 4, 2018 by DeepCoder786
• 1,720 points
0 votes

You can do this using dplyr and tidyr:

library(dplyr)
library(tidyr)
v %>% 
  mutate(string_name = strsplit(as.character(string_name), ",")) %>%
  unnest(string_name)
answered Dec 4, 2018 by Kalgi
• 52,310 points

Related Questions In Data Analytics

0 votes
2 answers

How to remove rows with missing values (NAs) in a data frame?

Hi, The below code returns rows without ...READ MORE

answered Aug 20, 2019 in Data Analytics by anonymous
• 32,930 points
13,007 views
0 votes
2 answers

how to convert a data frame into a list in R

Convert whole data frame into a list?? ...READ MORE

answered Sep 4, 2019 in Data Analytics by anonymous
• 32,930 points
346 views
0 votes
1 answer
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,150 points

edited Apr 12, 2018 by nirvana 20,142 views
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 32,930 points
628 views
0 votes
1 answer

How to apply list to a function which give data frame as output

If you use  tidyverse, you can use ...READ MORE

answered Apr 11, 2018 in Data Analytics by Sahiti
• 6,380 points
137 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
688 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
588 views