0

how does R read multiple answers for one varialbe from a CSV file? For instance, let's suppose that we have a variable called 'Relative Names'. A person will usually have many relatives and therefore a name for each hence under 'Relative Names" variable there will be multiple answers such as John, Kate, Peter, Annie etc...Is it better to have in the CSV file one variable containing all four names separated by space:

Relative Names
John Kate Peter Annie

or is it better to create a variable for each entry i.e.

Relatives Names 1 Relative Names 2 Relatives Name 3 Relative Names 4
John              Kate             Peter            Annie 

The problem with the second where you create an additional variable for each entry is that a second person might have for example six relatives then you will need to create Relative 5 and Relative 6 and so on for other people.

How does R deal best with multiple answers? What is the code to be used in R to extract multiple answers?

Psidom
  • 209,562
  • 33
  • 339
  • 356
N.Tabbal
  • 11
  • 2
  • You might consider a third option where you have only one column "relative names" and store each name in a separate row – talat Jun 03 '16 at 13:31
  • **R** doesn't do anything unless you tell it to. Please tell us the problem you're trying to solve, not how you want to solve it. You can parse text a dozen different ways. Every relative has all other relatives in a bidirectional relationship. What do you want to do? – Carl Witthoft Jun 03 '16 at 14:08
  • Store the relatives into a list, then convert it to data.frame. See more at http://stackoverflow.com/q/19330949/2824732 – Robert Jun 03 '16 at 14:22
  • This is a data formatting preference, not an R requirement. There are uses for both wide and long formats. – cory Jun 03 '16 at 14:24
  • I need to count the number of times a particular first name has been mentioned. How is it doable according to the first format where you have the names stored in one cell separated by space? How is it doable according to the second format where you have the names each stored in one column? I don't believe we can store each in a row for we have the names linked to other variables such as the name of the person to whom these names are the relatives. – N.Tabbal Jun 05 '16 at 18:55

0 Answers0