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,130 points
55 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
• 41,590 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 in Data Analytics by anonymous
• 27,960 points
4,989 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 in Data Analytics by anonymous
• 27,960 points
34 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,060 points

edited Apr 12, 2018 by nirvana 3,050 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

How to sort a data frame by columns in R?

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

answered Aug 21 in Data Analytics by anonymous
• 27,960 points
131 views
0 votes
1 answer
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
96 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
104 views