r

R: Is there a way to count the number of consecutive numbers in each row?

江枫思渺然 提交于 2021-02-11 04:30:12
问题 I'm wondering if there's a way to count the number of consecutive numbers in each row. Ideally, the output will be in column V6 and count the number of consecutive numbers in columns V1-V5. For example, Row 1 - 1, 2, 3, 4, 5 since there are 5 consecutive numbers, the output will be 5. I've attached the dataset that I have below for your reference. Thanks. enter image description here 回答1: Here is an option where we get the difference between alternate columns by removing the first column,

ggplot2 R fix x-axis label at a specific point relative to plot

一世执手 提交于 2021-02-11 04:28:09
问题 Say I have a plot like this: library(ggplot2) dat <- data.frame(x = 1:10, y = 1:10) ggplot(dat, aes(x = x, y = y)) + geom_point() + xlab("Test label") Does ggplot2 allow for fixing the xlab positioning at a specific point? Say I wanted the label to appear centered at the point where x = 7 (rather than the default centering). 回答1: This isn't exactly what you want, but you can adjust the horizontal justification in the theme options. This is relative between 0 and 1, not tied to the data

How to make a graph of clustered boolean variables in R?

拈花ヽ惹草 提交于 2021-02-11 04:27:35
问题 I have a dataset which consists entirely of boolean variables. Exactly like the transformed animal dataset below, only with many more columns. # http://stats.stackexchange.com/questions/27323/cluster-analysis-of-boolean-vectors-in-r library(cluster) head(mona(animals)[[1]]) war fly ver end gro hai ant 0 0 0 0 1 0 bee 0 1 0 0 1 1 cat 1 0 1 0 0 1 cpl 0 0 0 0 0 1 chi 1 0 1 1 1 1 cow 1 0 1 0 1 1 The goal is to rearrange the rows in such a way that groupings of similar membership patterns are

R: Is there a way to count the number of consecutive numbers in each row?

主宰稳场 提交于 2021-02-11 04:26:22
问题 I'm wondering if there's a way to count the number of consecutive numbers in each row. Ideally, the output will be in column V6 and count the number of consecutive numbers in columns V1-V5. For example, Row 1 - 1, 2, 3, 4, 5 since there are 5 consecutive numbers, the output will be 5. I've attached the dataset that I have below for your reference. Thanks. enter image description here 回答1: Here is an option where we get the difference between alternate columns by removing the first column,

How to make a graph of clustered boolean variables in R?

喜夏-厌秋 提交于 2021-02-11 04:26:19
问题 I have a dataset which consists entirely of boolean variables. Exactly like the transformed animal dataset below, only with many more columns. # http://stats.stackexchange.com/questions/27323/cluster-analysis-of-boolean-vectors-in-r library(cluster) head(mona(animals)[[1]]) war fly ver end gro hai ant 0 0 0 0 1 0 bee 0 1 0 0 1 1 cat 1 0 1 0 0 1 cpl 0 0 0 0 0 1 chi 1 0 1 1 1 1 cow 1 0 1 0 1 1 The goal is to rearrange the rows in such a way that groupings of similar membership patterns are

How to make a graph of clustered boolean variables in R?

眉间皱痕 提交于 2021-02-11 04:25:59
问题 I have a dataset which consists entirely of boolean variables. Exactly like the transformed animal dataset below, only with many more columns. # http://stats.stackexchange.com/questions/27323/cluster-analysis-of-boolean-vectors-in-r library(cluster) head(mona(animals)[[1]]) war fly ver end gro hai ant 0 0 0 0 1 0 bee 0 1 0 0 1 1 cat 1 0 1 0 0 1 cpl 0 0 0 0 0 1 chi 1 0 1 1 1 1 cow 1 0 1 0 1 1 The goal is to rearrange the rows in such a way that groupings of similar membership patterns are

Access Windows Registry inside R

為{幸葍}努か 提交于 2021-02-11 04:21:23
问题 How can I access the windows registry inside R. For example, I want to access the folder: [HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R\3.0.2] and the key called "InstallPath" to get: "C:\\Program Files\\R\\R-3.0.2" Many thanks! 回答1: You could use readRegistry() . On my machine: fp <- file.path("SOFTWARE", "R-core", "R", "3.1.0", fsep="\\") readRegistry(fp, "HLM") ## "HLM" eventually resolves to "HKEY_LOCAL_MACHINE" # $InstallPath # [1] "C:\\R\\R-current" (Also, for future reference, in this case you

Access Windows Registry inside R

☆樱花仙子☆ 提交于 2021-02-11 04:17:29
问题 How can I access the windows registry inside R. For example, I want to access the folder: [HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R\3.0.2] and the key called "InstallPath" to get: "C:\\Program Files\\R\\R-3.0.2" Many thanks! 回答1: You could use readRegistry() . On my machine: fp <- file.path("SOFTWARE", "R-core", "R", "3.1.0", fsep="\\") readRegistry(fp, "HLM") ## "HLM" eventually resolves to "HKEY_LOCAL_MACHINE" # $InstallPath # [1] "C:\\R\\R-current" (Also, for future reference, in this case you

Normalizing columns in R according to a formula

折月煮酒 提交于 2021-02-11 03:21:18
问题 Let's say I have a data frame of 1000 rows and 3 columns (column t0, t4 and t8). Each column represents a time point (0 hours, 4 hours and 8 hours). The data is gene expression: numeric (float): row.name t0 t4 t8 ENSG00000000419.8 1780.00 1837.00 1011.00 ENSG00000000457.9 859.00 348.39 179.00 ENSG00000000460.12 1333.00 899.00 508.00 I need to normalize the data according to a known result. I know that the average half-life of all rows (genes) should be 10 hours. So I need to find the

I got an error when exporting data from R

柔情痞子 提交于 2021-02-11 01:47:18
问题 When I wanted to export my results from R with this code, write.table(imp, "c:/immp.txt", sep="\t") I got this error: Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""mids"" to a data.frame Sorry for a simple question,I am new to R. Thanks for your help 回答1: It looks like you're trying to export a "mids" object, as opposed to a data frame. You'll need to convert it to a data frame before using write.table, which you should be