r-table

Make a table showing the 10 largest values of a variable in R?

心已入冬 提交于 2021-01-20 16:54:02
问题 I want to make a simple table that showcases the largest 10 values for a given variable in my dataset, as well as 4 other variables for each observation, so basically a small subset of my data. It would look something like this: Score District Age Group Gender 17 B 23 Red 1 12 A 61 Red 0 11.7 A 18 Blue 0 10 B 18 Red 0 . . etc. whereby the data is ordered on the Score var. All the data is contained within the same dataframe. 回答1: This should do it... data <- data[with(data,order(-Score)),]

Make a table showing the 10 largest values of a variable in R?

喜欢而已 提交于 2021-01-20 16:53:12
问题 I want to make a simple table that showcases the largest 10 values for a given variable in my dataset, as well as 4 other variables for each observation, so basically a small subset of my data. It would look something like this: Score District Age Group Gender 17 B 23 Red 1 12 A 61 Red 0 11.7 A 18 Blue 0 10 B 18 Red 0 . . etc. whereby the data is ordered on the Score var. All the data is contained within the same dataframe. 回答1: This should do it... data <- data[with(data,order(-Score)),]

R: Transpose the a results table and add column headers

十年热恋 提交于 2020-01-06 16:17:12
问题 Setting the scene: So I have a directory with 50 .csv files in it. All files have unique names e.g. 1.csv 2.csv ... The contents of each may vary in the number of rows but always have 4 columns The column headers are: Date Result 1 Result 2 ID I want them all to be merged together into one dataframe (mydf) and then I'd like to ignore any rows where there is an NA value. So that I can count how many complete instances of an "ID" there were. By calling for example; myfunc("my_files", 1) myfunc(

R error - Table of extent 0

人走茶凉 提交于 2019-12-11 17:48:25
问题 I'm a complete newbie to R so I'm currently trying to work my way through Youtube videos and books as I need to use R for a paper. I'm working in R Studio. I'm currently trying to get the frequency of one one of the features in my data. The value can either be 1 or 2 and I want to know how often I have 1 and how often 2. I'm importing my data like this: y <- read.table("Auszählung.csv", header = TRUE, sep = ";", comment.char ="", fill = TRUE, check.names = TRUE) And I'm trying to get the

Finding the original vectors from an interaction table

萝らか妹 提交于 2019-12-10 19:52:26
问题 A = c(1,2,3,2,1,2,2,2,1,2,3,2,1) B = c(2,3,2,3,2,2,1,1,2,1,2,2,3) mytable = table(A,B) What is the best solution to find back the two vectors from mytable ? Of course, it will not be the exact same vectors but the order of A compared to B has to be respected. Does it make sense? 回答1: You can use data.frame and rep : X <- as.data.frame(mytable) X[] <- lapply(X, function(z) type.convert(as.character(z))) Y <- X[rep(rownames(X), X$Freq), 1:2] Y # A B # 2 2 1 # 2.1 2 1 # 2.2 2 1 # 4 1 2 # 4.1 1 2

How to access values in a frequency table

会有一股神秘感。 提交于 2019-12-09 03:06:16
问题 I have a frequency table, counting the frequency of elements in a vector a = table(c(0,1,1,1,0,2,2,4,1,2,3,2,1,2,3,1,1,1,2,3,4,1,1,0)) a # 0 1 2 3 4 # 3 10 6 3 2 I know I can access the name by names(a). But when I tried to access the values of the SECOND row a[1, "0"] # Error in a[1, "0"] : incorrect number of dimensions a[1, 1] # Error in a[1, 1] : incorrect number of dimensions 回答1: This table is actually an array. x <- c(0,1,1,1,0,2,2,4,1,2,3,2,1,2,3,1,1,1,2,3,4,1,1,0) (a <- table(x)) # #