How to refer to a custom data frame in knitr document - r

I am new to knitr and would appreciate if someone could help me with a pointer on this.
Most examples I see using knitr/sweave create a data frame inside a chunk and then refers to that in the subsequent processing. However, what if I have massaged the raw into a data frame, and then want to use that. How do I do that?
I have tried saving the data frame as an R object, and then loading it inside a chunk, but I am not sure if this is the best way.

Related

Reverting a model.matrix in R back into a data.frame

I was wondering if someone knows if there's an easy and smart way to revert a matrix (that was generated by calling "model.matrix" on a data frame) back into a data.frame? The reason being that I am using the matrix in a function where the original data frame is not in the scope and I want to try something with the data frame without modifying the whole code (before I know if what I'm trying is even useful ๐Ÿ™‚).
Thanks in advance!

Extract data from tableau server to r data frame

We currently have a database that can only be accessed via a Tableau front end.
Is it possible with R (or any other means) to be able to extract the underlying data table into csv or txt? I don't really care what it ends up as so long as it is structured and can read into a data frame.
I can see from some looking around that I can use R scripting within Tableau but I cannot see a method to go the other way and pull data out of the Tableau Worksheet.
Any help appreciated!

Using `data()` for time series objects in R

I apologise if this question has been asked already (I haven't been able to find it). I was under the impression that I could access datasets in R using data(), for example, from the datasets package. However, this doesn't work for time series objects. Are there other examples where this is not the case? (And why?)
data("ldeaths") # no dice
ts("ldeaths") # works
(However, this works for data("austres"), which is also a time-series object).
The data function is designed to load package data sets and all their attributes, time series or otherwise.
I think the issue your having is that there is no stand-alone data set called ldeaths in the datasets package. ldeaths does exist as 1 of 3 data sets in the UKLungDeaths data set. The other two are fdeaths and mdeaths.
The following should lazily load all data sets.
data(UKLungDeaths)
Then, typing ldeaths in the console or using it as an argument in some function will load it.
str(ldeaths)
While it is uncommon for package authors to include multiple objects in 1 data set, it does happen. This line from the data function documentation gives on a 'heads up' about this:
"For each given data set, the first two types (โ€˜.Rโ€™ or โ€˜.rโ€™, and โ€˜.RDataโ€™ or โ€˜.rdaโ€™ files) can create several variables in the load environment, which might all be named differently from the data set"
That is the case here, as while there are three time series objects contained in the data set, not one of them is named UKLungDeaths.
This choice occurs when the package author uses the save function to write multiple R objects to an external file. In the wild, I've seen folks use the save function to bundle a description file with the data set, although this would not be the proper way to document something in a full on package. If your really curious, go read the documentation on the save function.
Justin
r

reaching max.print on R

I just found a bunch of weather data that I would like to play around with in glmnet in R. First I've been reading and organizing the data in R, and right now I am just trying to look at the raw data of each variable. Unfortunately, each variable has a lot of data and R isn't able to print it all. Is there a way I can view all the raw data in R or just in the file itself? I've tried opening the file in excel to no success. Thanks!
Try to use Frequency tables, you can group by segments.
str() , summary(), table(), pairs(), plots() etc. There are several libraries (such as decr) which facilitate analyzing numerical and factor levels. Let me know if you need help with any.

How to see which data is used in an example of a package

I am using the library(eventstudies)(Event Studies Package). In the sample they use:
(data(StockPriceReturns))
(data(SplitDates))
(head(SplitDates))
However I do not know how to set up my own dataset to use the package. My quesiton is:
How to look into the StockPriceReturns data?
I appreciate your answer!
I think you want to read a data set into a data frame or table.
I'm not familiar with that package, so I'm not sure about required format. If the data set you read in matches the schema of StockPriceReturns, I'm sure R will process it just fine. This PDF appears to explain it well.

Resources