r

Decapitalize UTF-8 special characters in R

大城市里の小女人 提交于 2021-02-17 04:10:06
问题 After I scraped a list of names, I have the following name in R: DAPHN\303\211 DE MEULEMEESTER If I use the function tolower, all the letters are set to lowercase, but not the special characters. What is the best way to achieve this? 回答1: The reason is that your locale is C. Non-ASCII special characters and their letter-case classifications are not recognized under that locale. You should be able to get it to work by switching to a UTF-8 locale: Sys.setlocale(locale='C'); ## [1] "C/C/C/C/C/en

How to fix missing labels in base R barplot

只谈情不闲聊 提交于 2021-02-17 03:39:35
问题 Hi i have trying to plot a barplot of number of staffs, however some of the labels on x axis is missing. How to fix this > dput(dat) structure(list(Name = c("John", "Jacky", "Jill", "Sam", "Arthur", "Aaron", "Jacob", "Joseph", "Martin", "Alan", "Albert", "Clare", "Frederick", "Florence", "David", "George", "Michael", "Doughlas", "Andrew", "Brian"), Clinc = c("DMMTC", "DMMTC", "DMMTC", "DMMTC", "CKDMTC", "CKDMTC", "CKDMTC", "CKDMTC", "Warfarin MTC", "Warfarin MTC", "Warfarin MTC", "Warfarin

How to compare the rows of two dataframes in R

杀马特。学长 韩版系。学妹 提交于 2021-02-17 03:36:51
问题 I'm trying to compare two columns of different data frames to create a new data frame. If the value of the row of the first col is less than the second, it will add a 1 to the new column. When the value is greater, it will add a 2 and so on. I'll give you an example. I have this df df1 <- data.frame(col=c(1,seq(1:9),9,10)) # col # 1 1 # 2 1 # 3 2 # 4 3 # 5 4 # 6 5 # 7 6 # 8 7 # 9 8 # 10 9 # 11 9 # 12 10 And this one, which has less rows df2<-data.frame(col2=c(3,6,8)) # col2 # 1 3 # 2 6 # 3 8

Removing rows in a data frame based on multiple criteria in R with loop function

淺唱寂寞╮ 提交于 2021-02-17 03:34:49
问题 I hope that I have formatted my question correctly as this is my first time posting and fairly new to R. Below is a small sample of some athlete movement data that I am currently using. My dataset has about 18000 row items and hence wanted to format it with quick R code. The sample data is attached herewith for your reference. I would like to remove rows of the data frame based on multiple criteria like when selecting price for particular company, with particular product and MRP between a

Euclidean Distances between rows of two data frames in R

做~自己de王妃 提交于 2021-02-17 03:29:36
问题 Calculating Euclidean Distances in R is easy. A good example can be found HERE. The vectorised form is: sqrt((known_data[, 1] - unknown_data[, 1])^2 + (known_data[, 2] - unknown_data[, 2])^2) What would be the fastest, most efficient way to get Euclidean Distances for each row of one data frame with all rows of another data frame? A particular function from apply() family? Thanks! 回答1: Maybe you can try outer + dist like below outer( 1:nrow(known_data), 1:nrow(unknown_data), FUN = Vectorize

kableExtra how to use cell_spec from a user defined range?

这一生的挚爱 提交于 2021-02-17 03:28:27
问题 First, the package kableExtra indeed produces awesome table. I just have an additional request : When running this example ( from the manual) iris[1:10, ] %>% select(-Species) %>% mutate_if(is.numeric, function(x) { cell_spec(x, "latex", bold = T, color = spec_color(x, end = 0.9), font_size = spec_font_size(x)) }) %>% kable("latex", escape = F, booktabs = T, linesep = "", align = "c") The cells are formated in each column. (1) How to adjust them to the entire table ? (2) Or to a user defined

R converting intraday tick dataframe to timesiers

折月煮酒 提交于 2021-02-17 03:01:52
问题 I have an intraday dataframe called SPX containing 5 minute tick data of the SPX index. It is currently in a dataframe and I wish to convert it into a wonderful timeseries. This is what it looks like currently: timestamp open high low close volume 1 2020-04-03 09:35:00 2516. 2524. 2513. 2522. 0 2 2020-04-03 09:40:00 2523. 2528. 2519. 2528. 45796799 3 2020-04-03 09:45:00 2528. 2538. 2526. 2533. 46888484 4 2020-04-03 09:50:00 2533. 2535. 2527. 2528 37476420 5 2020-04-03 09:55:00 2528. 2530.

R converting intraday tick dataframe to timesiers

别等时光非礼了梦想. 提交于 2021-02-17 03:01:03
问题 I have an intraday dataframe called SPX containing 5 minute tick data of the SPX index. It is currently in a dataframe and I wish to convert it into a wonderful timeseries. This is what it looks like currently: timestamp open high low close volume 1 2020-04-03 09:35:00 2516. 2524. 2513. 2522. 0 2 2020-04-03 09:40:00 2523. 2528. 2519. 2528. 45796799 3 2020-04-03 09:45:00 2528. 2538. 2526. 2533. 46888484 4 2020-04-03 09:50:00 2533. 2535. 2527. 2528 37476420 5 2020-04-03 09:55:00 2528. 2530.

Use roxygen2 to document multiple datasets in a single documentation object

ぃ、小莉子 提交于 2021-02-17 03:00:55
问题 I'm looking for an equivalent of @describeIn that will allow me to create a single documentation object for multiple R data objects. I had hoped that something like this: #' Tree Distances #' #' These datasets contain the distances between sets #' of 10-tip, 11-tip and 12-tip trees. #' #' @name treeDistances #' @keywords datasets "treeDistances10" "treeDistances11" "treeDistances12" would produce a single manual page that would apply to all three treeDistances## objects, similar to describing

Multiply and replace values in data frame according to condition in R

笑着哭i 提交于 2021-02-17 02:52:08
问题 I'm new to R and I've been trying to multiply and replace certain values in my data frame with no success. Basically, what I want to do is that when a value from my df (any column) is 0 < x < 1, multiplicate it by 10 and then replace that value with the result of this equation. A glimpse to my df just in case... 'data.frame': 404 obs. of 15 variables: $ D3: num 16.1 17.1 16.1 16.1 17.2 ... $ TH : num 9.9 8.6 9.7 7.7 7.6 7.6 8.7 9.8 9.8 7.7 ... $ D2 : num 33.3 29.3 30.3 29.3 33.3 ... $ D1 :