Mixed types in Shiny datatable - r

So I have a Shiny App that is basically a dataframe passed to the datatable function and formatted in a specific way (see picture below).
I want to put a string where there are 99999999999% values and blank cells while I keep the rest of the cells as numeric (I need the rest of the cells to be of numeric type so as to apply a color scale formatting on them). However, because of the very nature of dataframes, it is not possible to have different types in the same columns.
The question is: Do you know a way to have strings and numeric types in the same column of a data frame? Should I make some other workaround? In this case: Any idea?

Related

Dataframe updating in results but not when View() is used?

I have a markdown doc that shows the results of me changing a variable from 1 column (Industries) with multiple values in each cell, into a wide format where each value is now its own variable with values for TRUE or FALSE if it exists in a row from the initial single industries column.
When I run this code the results below the code show the wide format with TRUE/FALSE etc appropriately, but when i use View() to look at the wide format dataframe on its own, it just shows the single original Industries column with multiple values in each cell and I cant work out why.
Any ideas? I need to be able to merge my new wide set into a new dataset but as its still in the single column format i cant until I can work out why its not showing up properly.
Code and results showing successful wide variable layout
Dataframe not showing wide variable layout
Fixed it. I never assigned the changes to something new. I just needed to add a df <- at the start of the second chunk and then view that df instead.

How to import reactive datasets in Rshiny?

i m creating a risk dashboard , the problem is that i need the data set to be reactive , i have a simple dataset composed of countries (8) , sectors and values , what i want is that my app will be able to deal with different data sets for example if we change the colnames (country becomes pays) and we change the position of the col ,the app will recognize the column as country (in reality the data set is composed of an undefined number of variables with unkown names)
for example for the country column , i thought of creating a list that contains all country names and and when the first row of a column matches with a country from that list ,the column become names country
like that the problem is solved for one variable and what about the other ones
I think that's unnecesary complexity.
I suggest you to build an script to clean your data first with those specifications and then use it as a source.
You can use pattern recognition to match columns but be sure there aren't similar columns, for example, if you have two numerical variables there's a big problem.
Via Shiny I suggest you:
fileInput to import your database
Visualizate your database using DT
Create as many textInput boxes as columns you have
Manually change colnames using dplyr::rename and the boxes
Use the transformed database in your dashboard
Other options can be made using base::grep and dplyr.

How can I make two key columns from the different part of the column names in R?

I am going to do repeated measures ANOVA on my data, but to this point, my data is wide. Two independent (categorical) variables are spread across single responsive variable.
See the image: https://imgur.com/1eTWSIM
I want to create two categorical variables that take values from the different parts of the columns (circled on the screenshot). Subject numbers should be kept as a category. So after using gather() function, the data should look something like this:
https://imgur.com/SGM2N69
I've seen in a tutorial (that I can't find anymore) that you can create two columns from a single function, using different parts of the colnames (using "_" as a separator), but I can't exactly remember how it was done.
Any help would be appreciated and ask if anythings is not clear in my explanation.
I have solved the problem by using 'gather()' function first and then 'separate()' to separate it into two new columns. So I guess, if you want to make two key columns, first you have to make a single column containing both values and later separate it into two.
At least that is how I did it.

What's the easiest way to ignore one row of data when creating a histogram in R?

I have this csv with 4000+ entries and I am trying to create a histogram of one of the variables. Because of the way the data was collected, there was a possibility that if data was uncollectable for that entry, it was coded as a period (.). I still want to create a histogram and just ignore that specific entry.
What would be the best or easiest way to go about this?
I tried making it so that the histogram would only use the data for every entry except the one with the period by doing
newlist <- data1$var[1:3722]+data1$var[3724:4282]
where 3723 is the entry with the period, but R said that + is not meaningful for factors. I'm not sure if I went about this the right way, my intention was to create a vector or list or table conjoining those two subsets above into one bigger list called newlist.
Your problem is deeper that you realize. When R read in the data and saw the lone . it interpreted that column as a factor (categorical variable).
You need to either convert the factor back to a numeric variable (this is FAQ 7.10) or reread the data forcing it to read that column as numeric, if you are using read.table or one of the functions that calls read.table then you can set the colClasses argument to specify a numeric column.
Once the column of data is a numeric variable then a negative subscript or !is.na will work (or some functions will automatically ignore the missing value).

Concatenate excel cells with numbers without summing

I know you can use the concatenate function in excel to combine two strings in two different cells into one cell, but how do I do the same for cells with numbers in them? I have two columns as seen in the image below (I have started the process by hand to demonstrate what I want) and I want to concatenate the value to read into R to perform a choice experiment evaluation on the data but using concatenate sums the values.
You can also do the concatenation within R itself, by setting the column type to string, and then using the paste0(string1, string2) function.
You can use the & sign
=A1&C1
concatenate does also work in excel
=CONCATENATE(A1,C1)

Resources