Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的计算矩阵_R - Fatal编程技术网

R中的计算矩阵

R中的计算矩阵,r,R,体重指数(BMI)是一种生物特征测量方法,用于测量个人身高和体重之间的关系。BMI数据按以下向量进行汇编: imc即使你没有为你想要的输出提供一个合适的例子,我还是会根据我对你帖子的理解来回答你的问题 如果您希望将低、正常和超重的值简单分配给BMI值,可以使用dplyr library(dplyr) imc <- c(18, 19, 24, 25, 30, 35, 30, 20, 18, 15) table <- data.frame(imc) %>% mutate(i

体重指数(BMI)是一种生物特征测量方法,用于测量个人身高和体重之间的关系。BMI数据按以下向量进行汇编:


imc即使你没有为你想要的输出提供一个合适的例子,我还是会根据我对你帖子的理解来回答你的问题

如果您希望将
正常
超重
的值简单分配给BMI值,可以使用
dplyr

library(dplyr)

imc <- c(18, 19, 24, 25, 30, 35, 30, 20, 18, 15)

table <- data.frame(imc) %>%
  mutate(imcRangos = ifelse(imc < 18.55, "low", ifelse(imc > 30, "overweight", "normal")))

使用
cut
foverlaps

cut(imc, breaks = c(-Inf, 18.55, 30, Inf), labels = c("low", "normal", "overweight"))
#[1] low        normal     normal     normal     normal     overweight normal     normal    
#[9] low        low       
#Levels: low normal overweight

你能提供一个期望输出的例子吗?好的,我希望得到一个表,其中的值为:低、正常和超重
cut(imc, breaks = c(-Inf, 18.55, 30, Inf), labels = c("low", "normal", "overweight"))
#[1] low        normal     normal     normal     normal     overweight normal     normal    
#[9] low        low       
#Levels: low normal overweight