[R] to get how many participants in the dataframe and use it

R 复制代码
prop1 <- sum(GE_survey$`Q17_What department are you in` == "HSS") / nrow(GE_survey)
  1. nrow() and ncol() : Suppose you have a dataset my_data that contains information about customers, with each row representing a different customer and each column representing a different attribute (e.g., ID, name, age, etc.). You can use nrow(my_data) to find out how many customers are in the dataset and ncol(my_data) to find out how many attributes each customer record has.

  2. length() : If you have a vector my_vector containing the sales figures for each month of the year, you can use length(my_vector) to find out how many months of sales data you have.

  3. dim() : Suppose you have a matrix my_matrix that represents the results of a survey, with each row representing a different question and each column representing a different respondent. You can use dim(my_matrix) to find out how many questions were asked in the survey and how many respondents answered the survey.

  4. dimnames() : If my_matrix has row and column names indicating the questions and respondent IDs, respectively, you can use dimnames(my_matrix) to access and manipulate these names.

  5. attributes() : If you have a data frame my_df that contains information about products, including their names, prices, and quantities, you can use attributes(my_df) to view or modify the attributes of the data frame, such as its column names or class.

These functions are commonly used in data analysis and manipulation tasks to understand and work with the structure of your data.

相关推荐
uppp»14 分钟前
深入理解 Java 反射机制:获取类信息与动态操作
java·开发语言
玩电脑的辣条哥2 小时前
Python如何播放本地音乐并在web页面播放
开发语言·前端·python
ll7788115 小时前
LeetCode每日精进:20.有效的括号
c语言·开发语言·算法·leetcode·职场和发展
Jackson@ML6 小时前
Python数据可视化简介
开发语言·python·数据可视化
赵琳琅7 小时前
Java语言的云计算
开发语言·后端·golang
lly2024067 小时前
jQuery 杂项方法
开发语言
赵琳琅7 小时前
MDX语言的安全开发
开发语言·后端·golang
开开又心心的学嵌入式7 小时前
C语言——指针进阶应用
c语言·开发语言
开开又心心的学嵌入式7 小时前
C语言——指针基础知识
c语言·开发语言
lonelyhiker7 小时前
javascript的原型链
开发语言·javascript·原型模式