I just started using R in Jupyter notebook. There seems to be some issue displaying tibble table.
for example,
mtcars
Everything is normal.
If mtcars is converted to tibble,
car<-as_data_frame(mtcars)
car
The table displayed is totally screwed....
Anyone knows why? Do I need to set some options in jupyter notebook?
A follow-up question: How to control the number of rows for table output (not using head())? Is there any notebook options I can set? Is there any way that display the whole table with some page number button like those in R notebook?
Are you sure that you are using the latest version of Jupyter Notebook? I get exactly the same printout for the base data frame and the tibble.
As for the number of rows to show, I don't know of any notebook setting. If you don't want to use head(), you can always do:
mtcars[seq.int(15),]
with whatever number of lines you want instead of 15.
Related
I have a Jupyter notebook which runs a script in R (not python unfortunately).
In one of the cells of the notebook, I assign a text to variable (e.g. iso <- 'USA'). I'd like to change this, so that this cell is a list of text strings (e.g. iso <- c('USA', 'Canada'...)). Then, I'd like to run every subsequent cell for every item on the list.
How can I do this? Its basically a for loop that runs across multiple cells in the notebook.
Help!
I have a table of about 40 rows that I want to enter into a Jupyter notebook, I know the usual method but it's gonna take time to write down. Is there a more efficient way?
I understand that the command line can be used to view data, e.g. head(), tail(), etc.
However, I'd like to view the whole dataset. Is this possible within Jupyter Azure Notebooks?
(Untested) if you have a DataFrame object, calling the name should print the entire dataset.
For example, if your dataframe is named dta, just have
dta
at the end of a cell, and run that cell.
Power BI has a feature that lets you create visuals from R scripts. When you add data (columns) to the Values field, it automatically creates a data frame from those columns, which is calls "dataset"
It even shows the code it runs:
dataset <- data.frame(Col1, Col2, Col3, etc.)
My question is, how could I go about viewing the data in this dataframe?
I've tried running code like:
g <- xtabs(dataset)
g
print(g)
but it just returns the error: "No image was created. The code didn't result in creation of any visuals. Make sure your R script results in a plot to the R default device."
On the PowerBI website it says: 'Only plots that are plotted to the R default display device are displayed correctly on the canvas'. In simpler terms it means that if an object is printed to the console, it will not be displayed in PowerBI.
The tableHTML package let's you create HTML tables that will be displayed in the R default display.
library (tableHTML)
g <- tableHTML(dataset, rownames = FALSE)
print(g)
Note: you need to make sure tableHTML is installed in the library of R that is used by PowerBI. You can see the path for R used by PowerBI in the Global.options under 'R scripting'. Use the path that is displayed there in the code snipped below (this needs to be run from R/RStudio rather that PowerBI):
install.packages('tableHTML','/path/to/R/R-x.x.x/library)
You need to use a function that turns the table into a visual. If you install the gridExtra package in R, you should be able to do this in PowerBI:
g <- xtabs(dataset)
gridExtra::grid.table(dataset)
Bear in mind, the grid.table() requires a lot of detailed programming to control the image size, margins, font size, etc.
If you're just doing something simple like a crosstab, that's something you should be able to calculate as a Measure in PowerBI, and then use the built in table or matrix visuals.
I am using Jupyter Notebook to write my report and it would be convenient to include an output in my markdown.
The question below is a simillar question.
Jupyter notebook output in markdown
For example, I have a code cell with the code
In[1]: import random
a = random.randint(1,4);a
and the output was
Out[1]: 2
in my report, I would realy like to include this output just like
'the chosen number was 2'
however, as the 2 is a random number, it would be very convenient to have a way to include the variation a in my markdown like;
'the chosen number was %a'
kind of way.
Is there any way to achieve this?
It's not possible in the main notebook yet (although there are discussions about it) but there is an extension which should suit your purposes:
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/python-markdown/readme.html
It's contained within the ipython-contrib-extensions package, for which the install instructions are here:
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html