r

Import data from SQL Server to R

陌路散爱 提交于 2021-02-11 12:36:33
问题 I'm trying to import data from SQL Server to R. I was given the server name, user name and password to the SQL Server database. I've installed RODBC in R. But I don't know how to write the odbcConnect search as I don't have the database on my computer and I only know the server name. What should I do in such a situation? Thanks! 回答1: This is a typical SQL Server connection using DBI + odbc packages : library(DBI) conn <- DBI::dbConnect( odbc::odbc(), Driver = "SQL Server", Server =

Import data from SQL Server to R

半城伤御伤魂 提交于 2021-02-11 12:35:11
问题 I'm trying to import data from SQL Server to R. I was given the server name, user name and password to the SQL Server database. I've installed RODBC in R. But I don't know how to write the odbcConnect search as I don't have the database on my computer and I only know the server name. What should I do in such a situation? Thanks! 回答1: This is a typical SQL Server connection using DBI + odbc packages : library(DBI) conn <- DBI::dbConnect( odbc::odbc(), Driver = "SQL Server", Server =

R manipulation a character vector for a specific sequence

扶醉桌前 提交于 2021-02-11 12:34:53
问题 I have a list of item ids as below: ids <- c("12_a","23_b") Considering these item ids, I would like to generate a character variable as below for three groups (G1, G2, and G3). #for the first item Equal = (G1,12_a, Slope[0]), (G2,12_a, Slope[0]), (G3,12_a, Slope[0]); Equal = (G1,12_a, Slope[1]), (G2,12_a, Slope[1]), (G3,12_a, Slope[1]); Equal = (G1,12_a, Slope[2]), (G2,12_a, Slope[2]), (G3,12_a, Slope[2]); Equal = (G1,12_a, Intercept[0]), (G2,12_a, Intercept[0]), (G3,12_a, Intercept[0]);

How to export svg image to png file in r?

旧城冷巷雨未停 提交于 2021-02-11 12:33:42
问题 I have some svg images that I want to export as png files, using r. Is there a function that can do that? Until now I only found function that export r plots to png. But how could I export e.g. this example as a png? <svg height="100" width="100"> <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /> </svg> 回答1: rsvg https://github.com/jeroenooms/rsvg is designed to specifically to do this, and I'll say it does it very quickly. 回答2: The package convertGraph may be the

What is difference between dataframe created using SparkR and dataframe created using Sparklyr?

可紊 提交于 2021-02-11 12:32:33
问题 I am reading a parquet file in Azure databricks: Using SparkR > read.parquet() Using Sparklyr > spark_read_parquet() Both the dataframes are different, Is there any way to convert SparkR dataframe into the sparklyr dataframe and vice-versa ? 回答1: sparklyr creates tbl_spark. This is essentially just a lazy query written in Spark SQL. SparkR creates a SparkDataFrame which is more of a collection of data that is organized using a plan. In the same way you can't use a tbl as a normal data.frame

How to install CRAN packages in environment.yml

烈酒焚心 提交于 2021-02-11 12:32:33
问题 I'm using miniconda to manage my installation of data science packages. It is a workflow that I have somewhat established now, so I would like it to work in this case too. I also would assume it to work, since it is supposed to help in situations like this - where more dependencies than pure python is needed. I would like to install the python cdt toolbox. It is a pip -installable package available on PyPI but not in any conda channels. It requires PyTorch, available easily in PyPI and in

R shiny: insertUI and observeEvent in module

心不动则不痛 提交于 2021-02-11 12:32:23
问题 Using the diamonds dataset as an example, after a button is pressed, two pickerInput should appear. In the first one, the user chooses between three columns of the diamonds dataset. Once a value is selected the app should update the choices of the second pickertInput based on the unique values of the selected column. The app works well without modularizing it. After reading couple of discussions about modules, I still don't clearly understand how to properly declare reactive values for

Rcript Error in if (nx >= 2^31 || ny >= 2^31) stop(“long vectors are not supported”)

孤人 提交于 2021-02-11 12:32:10
问题 UPD: replaced merge to inner_join, new error: Error in UseMethod("tbl_vars") : no applicable method for 'tbl_vars' applied to an object of class "function" Calls: inner_join ... tbl_vars -> new_sel_vars -> structure -> tbl_vars_dispatch I am trying to run my R-script from command line, but it is return error: Error in if (nx >= 2^31 || ny >= 2^31) stop("long vectors are not supported") : missing value where TRUE/FALSE needed Calls: merge -> merge.data.frame Execution halted What it's mean?

Crating Kernel density estimate for polygon in R

不想你离开。 提交于 2021-02-11 12:29:30
问题 I Have a shapefile of polygons and another one of points that are distributed over the polygons. I would like to create a kernel density estimate for each polygon based on the points it contains. unfortunately I was only able to create squared KDEs with the kde2d function from the MASS package. I would like the KDEs to be shaped as the polygons. Any suggestions? kde1 <- kde2d(poly$X, poly$Y, n=100,) enter image description here 回答1: You can use the spatstat package for this. Here is an

R calculating grouped frequency table with percentage [duplicate]

天大地大妈咪最大 提交于 2021-02-11 12:29:29
问题 This question already has answers here : Calculate Percentage for each time series observations per Group in R (2 answers) Closed 4 years ago . Giving the following data.frame , I would like to calculate the occurance of each variable of VAR and the percentage of these occurence by the grouping variable GROUP : GROUP<-c("G1","G2","G1","G2","G3","G3","G1") VAR<-c("A","B","B","A","B","B","A") d<-data.frame(GROUP,VAR) With table() , I get a nice frequency table, counting the occurences of all