Displaying 2 results from an estimated 2 matches for "name_singular".
2005 Oct 25
2
data.frame-question
...answer for you.
I tried a lot and read through the manuals, but I still have the
following problem:
I have 2 data-frames:
Number<-as.numeric (Number)
Name<-as.character (Name)
TAB1<-data.frame (Name,Number)
- it looks like this:-
Name Number
A 2
A 3
A 6
B 8
B 12
B 7
C 8
D 90
E 12
E 45
佲仸
Name_singular<-as.character (Name_singular)
TAB2<-data.frame (Name_singular)
# it looks like this:
Name_singular
A
B
C
D
E
-My result should be a data-frame, where the first column is
Name_singular and the second column should be the sum of the numbers
where Name ==Name_singular.-
For example:
TAB3:
Name...
2005 Oct 27
1
data.frame-question]
...1
3 A 1
4 B 1
5 B 1
6 B 1
7 B 1
8 B 1
9 C NA
> TAB3 <- with(TAB1, tapply(Number, Name, sum, na.rm=TRUE))
> TAB3
A B C
3 5 0
> TAB3 <- as.data.frame(TAB3)
> TAB3
TAB3
A 3
B 5
C 0
> colnames(TAB3) <- c("Name_singular", "Sum")
Error in "dimnames<-.data.frame"(`*tmp*`, value = list(c("A", "B", "C" :
invalid 'dimnames' given for data frame
> TAB3
TAB3
A 3
B 5
C 0
> str(TAB3)
`data.frame': 3 obs. of 1 variable:
$ TAB...