Hello R people, I have a data file with 101 numeric variables: one variable called IDN (the individual's unique id number, which I need to retain, and which ranges from 1000 to 1320; some numbers are obviously skipped), and V1 to V100 (each has a value of 0 or 1; these 100 variables represent sequentially ordered days and whether a characteristic was present or absent--e.g., v1 is day 1 and a "1" means the characteristic is present; v10 is day 10 and "0" means the characteristic is absent).
This may be child's play for many on this list, but how do I transform this data file to two columns, one called "id" and another column named "c" with 100 rows? I think it will end up being a 1000 row file. I've read some and think that I'm trying to "melt" my existing data. I can transpose the v1 to v100 with t(v1 to v100) but then I'm unclear on how to automatically generate 100 identical IDN's for each case and variable and then put them together. This may be redundant, but for the sake of clarity, what I'm trying to do is get from this: IDN V1 V2 V3 V100 1 0 1 0 . . . 1 2 1 1 1 . . . 0 4 0 1 0 . . . 1 . . 100 0 1 0 . . . 1 To this: id c 1 0 1 1 1 0 . . . [continue 96 more times for c4 - c100] 1 1 2 1 2 1 2 1 . . . [continue 96 more times for c4 - c100] 2 0 . . . [then repeat this for the next 98 cases] 100 0 1 0 1 Thank you very much. PJ [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.