Specific variables calculation [closed] - r

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Hello,I have an issue.I have an excell and I want to calculate and to find Min. =0.000 etc..but I find Min. =1.700 etc. What am I doing wrong here?

I believe the problem is your inclusion of & grade as a term in your filter step.
What's going on is that R wants to interpret each of these terms (exam=="S1", year==2018, grade) as a logical value. When it converts grade to logical, 0 becomes FALSE and all other values become TRUE (try as.logical(-1:1) to see an example), so the zero values in your data get removed.
Just delete & grade from your code.

Related

Computed variable gives unexpected counts [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I have a problem with the coding of some variables. I am working on data for Lebanon on R on two different datasets, the World Value Survey and the Arab Barometer. Regardless of the dataset I am using, when I try to code a variable referring only to one country (in this case Lebanon), the values of the variable at the end of the coding are entirely wrong.
I have tried the same coding with other variables and with another dataset, but the problem remains, and the values are still much larger than they should be.
As can be seen from the values in the 'table' command, the values after encoding are very different.
As a beginner, I'm sure my question will be trivial, but I'm asking for help to unblock the situation.

r function for counting specific row of 2 columns [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I need help how to compare 2 columns in r studio but only in the first 5 observations
code used first was
damgeByage<-table(test$Vehicle_Age,test$Vehicle_Damage)
damgeByage
which give me all 186 observation but only want the first 10 oobservation of both columns
I
We can subset the data with row index
table(test[1:10, c("Vehicle_Age", "Vehicle_Damage")])
akrun's answer works or you can also use:
table(test$Vehicle_Age[1:10],test$Vehicle_Damage[1:10])
the table is also subsettable if you just wanted the first 10 rows of the results:
damgeByage<-table(test$Vehicle_Age,test$Vehicle_Damage)
damgeByage[1:10,]

Find duplicate registers in R [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have an excel file with a list of emails and channels that collected it. How can I know how many emails per channel are duplicated using R and automate it (every time I import a different file just have to run it and get the results ) ?
Thank you!!
Assuming the "df" dataframe has the relevant variables under the names "channel" and "email", then:
To get the number of unique channel-email pairs:
dim(unique(df[c("channel", "email")]))[1]
To get the sum of all channel-email observations:
sum(table(df$channel, df$email))
To get the number of duplicates, simply subtract the former from the later:
sum(table(df$channel, df$email)) - dim(unique(df[c("channel", "email")]))[1]

Finding the 2nd Max value in R data table [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a data table that has a int column that is counting the iteration of a test that I've preformed. So the first time I preformed the test, Table$Column == 1 and the second time Table$Column == 2 and so on and so forth.
However, there are times when a test breaks or I don't want to use the results from a particular test run. I have code that compares the current run vs. the previous run that looks like this.
vLatest<-max(Table$Column)
vPrevious<-max(Table$Column)-1
But since I sometimes omit results, it breaks vPrevious. How could I replace the "-1" with a function that finds the "2nd" max value?
This should work:
vPrevious <- sort(Table$Column, decreasing=T)[2]
We first sort in descending order and then pick the second element.

Getting the Mean by a Factor [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
All, I wrote this function but it has flaws:
X=cbind(rep(1:5,4),rep(c(1,2,4,8,16),2),c(3.4,4,45,6,4,2,36,4,34,7,8,0,2,4,5,7,9,12,23,1))
getXbarl<-function(Y,l){
xbar=tapply(Y,l,mean)
return(matrix(xbar[l]))#***
}
#It works for the first row:
getXbarl(X[,3],X[,1])
#but not the second row, because the factors are no longer 1:5 here.
getXbarl(X[,3],X[,2])
Please help me write a fix. The issue is that for xbar[l]***, it no longer corresponds to the index.
I think you need ave
ave(X[,3], X[,2])
As a function
getXbarl2 <- function(Y,l) matrix(ave(Y,l))
identical(getXbarl(X[,3], X[,1]), getXbarl2(X[,3], X[,1]))
#[1] TRUE
getXbarl<-function(Y,l){
xbar=tapply(Y,l,mean)
l2=factor(l,labels=1:length(xbar))
return(matrix(xbar[l2]))
}
X=cbind(rep(1:5,4),rep(c(1,2,4,8,16),2),c(3.4,4,45,6,4,2,36,4,34,7,8,0,2,4,5,7,9,12,23,1))
getXbarl(X[,3],X[,1])
getXbarl(X[,3],X[,2])

Resources