I have a dataset. In that I have to add a new column. The value of this new column will come from the mu and timepoint columns. If mu contains ae and timepoint contains 1 then it will take the value of number 1 from ae and so on.
Dataset description
Related
My goal is to administer both variables and their values in a spreadsheet.
Basically I want to be able to add the new values for a new year in a new column and load them into R.
I then want to assign the variables named in the first column with the corresponding value in either one of the second or third column.
Input spreadsheet:
Variable
Year2013
Year2018
age
12
17
pets
c(cat,dog,elephant)
c(dog,mouse)
cars
cars$name
cars$name
Desired Output:
For year 2013
import("dataspreadsheet.csv")
derived from this -->
age <- 12
pets <- c(cat,dog,elephant)
cars <- cars$name
Is there any way to tell R to make this assignment?
I am trying to use if and ifelse statement to create a new column in my dataframe based on the values of an existing column. For example, I have a variable column which has numbers from 1 to 10000. I want to categorize them into 8 buckets (using 1250 size) in my new column. So if I have 1 in my column, I should get b1 in the new column. If I have 9999, I should get b8, etc. My if else code is failing so far.
Thanks!
You can use cut :
paste0('b', cut(1:10000, 8, labels = FALSE))
Replace 1:10000 by column values (df$colum_name).
I have two different data frame below, Scale is the allowable score range/point and in this case is 1-5. Score is the actual score provided by participant using the value defined in Scale. I need count the number of score for each scale point in the Score Data frame. for example, there are two counts of 2 in Score,while zero count of 1.
a<-c(1,2,3,4,5)
b<- c(2,3,4,5,3,4,4,3,3,5,2,3,3)
Scale<-data.frame(Scale =a)
Score<-data.frame(Score=b)
I tried aggregate, but it only identify unique value it found in one data frame and couldn't consult with another one. For example, it will not be able to find there is zero score for 1 in Score and only return counts for 2,3,4,5.
Anyone has any good idea?
Like this?
> table(factor(Score$Score, levels = a))
1 2 3 4 5
0 2 6 3 2
How to change a value in a single row, when I've got the name of the value from another column (same row)?
Example: I've got the that data frame:
id sex age
1 k.8 female 17
I know the id, I want to change age in this particular row.
call that table x
x[x$id == "k.8", "age"] <- 3
you should look into what [] and [[]] do
I have a report Which having 10 column in which 5 or more column name is score i want to add all Score Column value into a Total Score Column. how can we do this ?
i want to write a expression or anything which can add only Score Column value.