Dear R users,
I have data frame of 100 points. Now I want to create one new column (e.g. experiment) with first 50 row names "math" and last 50 row names "physics".
I am using rep()
but still not able to do that
data.frame(rep("math",100)) -> PB$experiment
The given code taking whole data points, it's not taking half 50 c(1:50)
Could you please provide some information on that.
thanks
Your example code does rep("math",times=100)
, meaning it gives you "math" a 100 times. You probably want: rep(c("math", "physics"),each=50)
.
Thanks for the reply. But it's not working.
is there any possibility to give names by selecting rows such as [,c(1:50)]
I mean If I want to give 1st 10 row as "math" and remaining 90 rows as "physics" then how can we do that.
rep(c("math", "physics"), times = c(10,90))
system
Closed
September 14, 2020, 7:43pm
7
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.