How to Convert .Rdata Format into Text File Format

How to convert .Rdata format into text file format

load("yourData.RData")
ls() #returns a list of all the objects you just loaded (and anything else in your environment)
write.csv(theItemOfInterestFromYourDRadataFileAsThereMayBeMoreThanOneThingInthere,
file="yourCSV.csv")

Convert R objects to csv/text files

If you need to save generic R objects, you would typically use saveRDS (this is preferable to using save for a single object). If the file must be ASCII, saveRDS,save, and serialize all have the parameter ascii=TRUE, with serialize producing the most readable output.

If you need the file to be human readable ASCII, you were on the right track with dump. The only change you need is that dump takes the name of the object as its argument:

dump('variant', file="variant_file")

Here is an example of the sort of output from each of these options for a random neural network:

> serialize(model,connection = (con<-file('nn','w')),ascii = TRUE)
NULL
> close(con)
> writeLines(readLines('nn',n=10))
A
2
197122
131840
787
13
14
3
11
2

> dump('model',file='nn2')
> writeLines(readLines('nn2',n=20))
model <-
structure(list(n = c(11, 2, 1), nunits = 15L, nconn = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 38), conn = c(0, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 0, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), nsunits = 14,
decay = 0.3, entropy = FALSE, softmax = FALSE, censored = FALSE,
value = 198533.158122471, wts = c(19.0054841585536, 2.23487502441887,
4.18125434527288, -6.18031807633724, 1.74046449146894, -12.6452914163319,
4.36482412477615, -13.8535055297175, -2.86352652003103, -8.26639784261127,
-12.6981294199594, 4.6795318281078, 21.4576975495026, 2.3237431117074,
6.11977661730472, -4.72698798667361, -0.850474104016898,
-13.6710933522033, 4.09687948057462, -12.53360483838, -4.62974366307091,
-10.2276751641509, -11.5384259593477, 0.393593676803197,
11.9212104035313, -23.389751188319, 20.3888183920005, -0.900624040655219,
1.0351758513862, -0.343608722841881, -1.66543302778472, -1.29803652137646,
0.242127071364901, 0.994889406131462, -2.30836053849945,
0.190090309268229, -0.35494347864244, -0.201148348574871),
convergence = 0L), .Names = c("n", "nunits", "nconn", "conn",
"nsunits", "decay", "entropy", "softmax", "censored", "value",
"wts", "convergence"), class = "nnet")

Converting Rdata files to CSV - Error in data.frame arguments imply differing number of rows

That answer was designed to handle object of class-'data.frame'. You only have an object of class-'list' which happens to have items that are dataframes. So there isn't an object with the name "2" in you workspace but there is an element in the 'dataa'-list that is named "2" and all of the other elements appear to also be dataframes, so why not use:

lapply( names(dataa), function(nam) write.csv( data[[nam]], file=paste0(nam, ".Rdata") ) )

Loading data from TXT file and conversion to TSE format in TraMineR

This answer draws on details of the data the OP gave in a mail to the TraMineR-mailinglist.

As already pointed out by Gilbert in the comment, you firstly have to import the text file using read.table() or read.csv().

To me, your data already seems to be in time stamped event sequences (TSE) format, so there is no need of conversion. Rather, the problem is that sequence analysis uses discrete time data and your data seems to be on a continous scale. Therefore, you secondly need to define a reasonable time scale for your own research question. Considering your data, I think that you do not need realtime data but that you could use process time in a less precise granularity (round up to seconds, for example).

After this redefinition, you can thirdly use the TSE_to_STS function of the package TraMineRextras to transform your dataframe into STS format. Then you can finally define a sequence object using TraMineR.

Please, consult also the chapter 4 and 5 of the TraMineR manual.



Related Topics



Leave a reply



Submit